ERROR: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Star Strider
2012-9-19
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.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!