???error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts.
조회 수: 2 (최근 30일)
이전 댓글 표시
g=fileread ('e:\dfiles\a(3).dat');
f=['e:' filesep 'dataf'];
x=size(g,1);y=size(g,2);
a=dir(f);
data(x,y,6)=zeros(1,1,1);
j=0;
for i=3:8
j=j+1;
data(x,y,j)=importdata(fullfile(f,a(i).name)); // error in this line
end
댓글 수: 0
채택된 답변
Geoff
2012년 4월 11일
I think you have a slight misconception about how to initialise your data sets. Start with this:
data(x,y,6)=zeros(1,1,1);
I think what you mean is this:
data = zeros(x,y,6);
Now, I'm assuming your data files specify a row and column count as the first two values? Is this on the first line? Is every file the same?
In that case you may need to specify the NHEADERLINES parameter for importdata
doc importdata
I'll assume spaces as delimiter and 1 header line:
for n = 1:6
filename = fullfile(f,a(n+2).name);
X = importdata(filename, ' ', 1);
if size(X,1) ~= x || size(X,2) ~= y
warning( ['Ignoring ' filename ': Wrong dimensions'] );
continue;
end
data(:,:,n) = X;
end
We can only hope that your values for x and y are correct from that call to fileread
추가 답변 (1개)
Walter Roberson
2012년 4월 11일
What you show is going to give you a problem unless importdata() happens to import exactly one value.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!