ERROR: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

1 visualización (últimos 30 días)
Hello everyone, I am trying to debug an error in my code, but I am not sure what the problem is. I think it might be very simple, but I am not catching it. I have a list of .mat files in my current working directory, and I want to store specific file names in a variable "Incl". These file names begin with "PE". Here is my code:
DIR = dir;
STRCMP = 'PE';
for I = 1:length(DIR),
TF(I) = strncmpi(DIR(I).name,STRCMP,2);
end
%Logical 1 if PE file is found or 0 if PE file is not found
Ind = find(TF);
%Stores index location of each PE file (to be compared with DIR)
for J = 1:length(Ind)
Incl(J,1) = DIR(Ind).name;
end
My problem is during the last for loop. I am trying to call upon the specific file names in my directory that correspond to the index values I stored. These Dir(Ind).name variables are char format. I am trying to store them into Incl. Can anyone help me determine why I am getting this error?

Respuesta aceptada

Star Strider
Star Strider el 19 de Sept. de 2012
I suggest:
for J = 1:length(Ind)
Incl{J,:} = DIR(Ind(J)).name;
end
Creating Incl as a cell with an open-ended column reference allows for the filenames to be more than one character long and also for their not all being the same length. (That may not be a problem for you but was a consideration in the code snippet I tested on my machine.) Also, you have to reference Ind by your loop index. (You would quickly have discovered that.)

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by