Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matlab arrays

Status
Not open for further replies.

shivas007

Bioengineer
Sep 11, 2005
8
Hi all,
Im working on a program which imports ( and loads) all the .mat files in to the workspace. The number of .mat files in the directory may vary to a significant number(say at around 1000 frames).To just give you an idea of what im doing, below is my code that i have written

files = dir('C:\Datasets\Number_of_Frames\*.mat');
for i=1:length(files)
eval(['importdata ' files(i).name ]);
eval(['frame_' int2str(i) '=ans']);
end

Im getting the output for this program correctly in the workspace, like below

frame_1 <2000X100 double>
frame_2 <2000X100 double>
frame_3 <2000X100 double>
frame_4 <2000X100 double>
frame_5 <2000X100 double>
frame_6 <2000X100 double> ..so on until frame_n

My problem here is that I want to push all these frames in to an array (say list[]), so that i can reference the frame_1 as list(1),frame_2 as list(2) and so on. I want to do this array functionality in the above mentioned program itself and added a statement for array in the routine as follows ( array d[] and statements d:),:,i).. and d{i}, i tried both)

files = dir('C:\Datasets\Number_of_Frames\*.mat');
for i=1:length(files)
d=[];
eval(['importdata ' files(i).name ]);
d:),:,i)= eval(['frame_' int2str(i) '=ans']);
%%%% d{i}=[{eval(['x_' int2str(i) '=ans'])}];
end

But im getting an error like

" ??? Error: The expression to the left of the equals sign is not a valid target for an assignment.

Error in ==> importing_multiple at 5
d:),:,i)= eval(['frame_' int2str(i) '=ans']);"

and the same error when i used d{i} too.

Can anyone of you guys please help me out in this array implementation.I even tried using the cell arrays but im not able to get the syntax right.Please pour in your valuable help.Thanks a zillion.

 
Replies continue below

Recommended for you

Hi,
If I've weell understood your problem you can use the cell array in such a way

files = dir('C:\Datasets\Number_of_Frames\*.mat');
for i=1:length(files)
d={};
eval(['d{' int2str(i) '}=load(files(' int2str(i) ').name);']);
end

d is a cell array that contains all your frame_i array

Gianluca
 
Its executing but with 'd' as a null array, like if we give the command(below) its showing the answer as a null array.
d{1,1}

ans =

[]
 
Sorry for my late!

There is an error in my code...
This is the right


files = dir('C:\Datasets\Number_of_Frames\*.mat');
d={};
for i=1:length(files)
eval(['d{' int2str(i) '}=load(files(' int2str(i) ').name);']);
end

Hi
Gianluca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor