×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Matlab arrays

Matlab arrays

Matlab arrays

(OP)
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.     

        

RE: Matlab arrays

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

RE: Matlab arrays

(OP)
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 =

     []

RE: Matlab arrays

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources