Question

I have been making a loop that assign Mx names for 121 different files in a folder.

    allFiles = dir( '*.xls''String' );
allNames = { allFiles.name };

for ii = 1:length(allNames) M(ii) = xlsread(allFiles(1i)); 
end

Trouble is that there is no errormessage, but it isn't assigning any names for the values/files i want it to.

listing = dir('*.xls');

disp(listing);

When i make a simple dir() it tells me

 121x1 struct array with fields:
    name
    date
    bytes
    isdir
    datenum

But i have to make it a String in order for xlsread() to work.

What i want it to is to make a name for each file so i can handle them in matlab, (ie. addtion of two matrices).

What can be wrong?

Was it helpful?

Solution

This question is basically just typos and confusion of variables:

allFiles = dir('*.xls'); % correct file extension

for ii = 1:size(allFiles, 1) % allFiles has one row per file, so loop over those
    M{ii} = xlsread(allFiles(ii).name); % store matrix in cell array
end

Note that M is now a cell array, because you can't store multiple matrices in a matrix or vector.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top