???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 中查找有关 Large Files and Big Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!