???error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts.

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Geoff
Geoff le 11 Avr 2012
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 commentaires
dee koshy
dee koshy le 11 Avr 2012
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 le 11 Avr 2012
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'}

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 11 Avr 2012
What you show is going to give you a problem unless importdata() happens to import exactly one value.
  1 commentaire
dee koshy
dee koshy le 11 Avr 2012
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by