???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

채택된 답변

Geoff
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
  댓글 수: 2
dee koshy
dee koshy 2012년 4월 11일
Geoff,
The file holds some coordinate informations( 3 columns) and has upto 250 lines of this.
2.8700000e+002 1.1800000e+002 -9.3804749e-001
1.3400000e+002 7.5000000e+001 2.3424967e+000
9.4000000e+001 1.7000000e+001 -7.7416268e-001
9.4000000e+001 2.0700000e+002 -2.1432561e+000
1.0600000e+002 1.7000000e+001 -8.7160374e-001
1.0600000e+002 2.0700000e+002 -2.1432561e+000
1.3300000e+002 1.7000000e+001 -1.1160771e+000
Well,now only the warning is coming up.X is a structure after importdata right? I'm not able to store it in the data(:,:,n) array
dee koshy
dee koshy 2012년 4월 11일
size of X is (1,1)
X =
data: [405x3 double]
textdata: {'2.8700000e+002' '1.1800000e+002' '-9.3804749e-001'}
colheaders: {'2.8700000e+002' '1.1800000e+002' '-9.3804749e-001'}

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 11일
What you show is going to give you a problem unless importdata() happens to import exactly one value.
  댓글 수: 1
dee koshy
dee koshy 2012년 4월 11일
i have to read a dat file in text format. Basically i have to store the values from the dat files into an array of strings or something so that i can compare an input file to this database

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by