From: David Young on
When the .mat files were created, what was the name of the variable that was saved to each one? Did the name of the variable correspond to the name of the .mat file, or was it always x or something like that?

If the same variable was saved each time, but the file name changed, the problem is easier.
From: Mohammed on
Thanks for your time. Here is my code:

clear;
clc;
Number_images = 383;
for j=1:Number_images
if j<10
temp = importdata(strcat('d6000_c_2_00',num2str(j),'.tif'));
end
if (j>=10) && (j<100)
temp = importdata(strcat('d6000_c_2_0',num2str(j),'.tif'));
end
if j>=100
temp = importdata(strcat('d6000_c_2_',num2str(j),'.tif'));
end

eval(sprintf('x%d=temp(:,:,1:1);', j));
eval(sprintf('save x%d x%d;', j, j));
end

Unfortunately, I have been using eval.
I have 383 .tif image files which I have imported and then saved as .mat files. The filename and variable names are the same.
The images are from a thermal camera which records the heating and cooling of a material. Basically, what I ultimately want to do is select a pixel or a region and observe how it changes in time. I thought it might be easier if I put all the data into one matrix. It's been a long time since I used Matlab and it feels like I have to re-learn a lot of the things I have done before.
From: Mohammed on
"David Young" <d.s.young.notthisbit(a)sussex.ac.uk> wrote in message <hrbs0s$go9$1(a)fred.mathworks.com>...
> When the .mat files were created, what was the name of the variable that was saved to each one? Did the name of the variable correspond to the name of the .mat file, or was it always x or something like that?
>
> If the same variable was saved each time, but the file name changed, the problem is easier.

Thanks for your time. Here is my code:

clear;
clc;
Number_images = 383;
for j=1:Number_images
if j<10
temp = importdata(strcat('d6000_c_2_00',num2str(j),'.tif'));
end
if (j>=10) && (j<100)
temp = importdata(strcat('d6000_c_2_0',num2str(j),'.tif'));
end
if j>=100
temp = importdata(strcat('d6000_c_2_',num2str(j),'.tif'));
end

eval(sprintf('x%d=temp(:,:,1:1);', j));
eval(sprintf('save x%d x%d;', j, j));
end

Unfortunately, I have been using eval.
I have 383 .tif image files which I have imported and then saved as .mat files. The filename and variable names are the same.
The images are from a thermal camera which records the heating and cooling of a material. Basically, what I ultimately want to do is select a pixel or a region and observe how it changes in time. I thought it might be easier if I put all the data into one matrix. It's been a long time since I used Matlab and it feels like I have to re-learn a lot of the things I have done before.
From: Oleg Komarov on
"Mohammed "
> "David Young"
> > When the .mat files were created, what was the name of the variable that was saved to each one? Did the name of the variable correspond to the name of the .mat file, or was it always x or something like that?
> >
> > If the same variable was saved each time, but the file name changed, the problem is easier.
>
> Thanks for your time. Here is my code:
>
> clear;
> clc;
> Number_images = 383;
> for j=1:Number_images
> if j<10
> temp = importdata(strcat('d6000_c_2_00',num2str(j),'.tif'));
> end
> if (j>=10) && (j<100)
> temp = importdata(strcat('d6000_c_2_0',num2str(j),'.tif'));
> end
> if j>=100
> temp = importdata(strcat('d6000_c_2_',num2str(j),'.tif'));
> end
>
> eval(sprintf('x%d=temp(:,:,1:1);', j));
> eval(sprintf('save x%d x%d;', j, j));
> end
>
> Unfortunately, I have been using eval.
> I have 383 .tif image files which I have imported and then saved as .mat files. The filename and variable names are the same.
> The images are from a thermal camera which records the heating and cooling of a material. Basically, what I ultimately want to do is select a pixel or a region and observe how it changes in time. I thought it might be easier if I put all the data into one matrix. It's been a long time since I used Matlab and it feels like I have to re-learn a lot of the things I have done before.

Don't save them separately.
First preallocate a big matrix (383 matrices of size 256x320):

bigOut = zeros(256*383,320);

then replace:
temp = importdata(...);
bigOut(j*256-255:j*256) = importdata(...);

Regards

Oleg
From: Steven Lord on

"Mohammed " <mohammed98221(a)gmail.com> wrote in message
news:hrc2qt$ge1$1(a)fred.mathworks.com...
> Thanks for your time. Here is my code:
>
> clear;
> clc;
> Number_images = 383;
> for j=1:Number_images
> if j<10
> temp = importdata(strcat('d6000_c_2_00',num2str(j),'.tif'));
> end
> if (j>=10) && (j<100)
> temp = importdata(strcat('d6000_c_2_0',num2str(j),'.tif'));
> end
> if j>=100
> temp = importdata(strcat('d6000_c_2_',num2str(j),'.tif'));
> end
> eval(sprintf('x%d=temp(:,:,1:1);', j));
> eval(sprintf('save x%d x%d;', j, j));
> end
>
> Unfortunately, I have been using eval. I have 383 .tif image files which I
> have imported and then saved as .mat files. The filename and variable
> names are the same. The images are from a thermal camera which records the
> heating and cooling of a material. Basically, what I ultimately want to do
> is select a pixel or a region and observe how it changes in time. I
> thought it might be easier if I put all the data into one matrix. It's
> been a long time since I used Matlab and it feels like I have to re-learn
> a lot of the things I have done before.

As you know, if you've been reading this group for any length of time, using
that construct is strongly discouraged (see question 4.6 in the newsgroup
FAQ if you haven't been reading the group for an explanation as to why it's
discouraged) but in this case we can get around that. Note that in the code
below I'm assuming all the x* matrices are the same size and that you know
that size ahead of time.

% Get the list of files
D = dir('x*.mat');

% Assume all the x's are 100-by-200
rowsInX = 100;
colsInX = 200;

% Preallocate
storedData = zeros(rowsInX, colsInX, numel(D));

for k = 1:numel(D)
% x* is a field of dataFromFile
dataFromFile = load(D(k).name);

% strip off the .mat extension to get the name of the variable
fieldname = D(k).name(1:end-4);

% use dynamic field name indexing to refer to the variable/field
storedData(:, :, k) = dataFromFile.(fieldname);
end

If they're not the same size, use a cell array.

storedData = cell(1, numel(D));

storedData{k} = dataFromFile.(fieldname);

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ