Can anybody tell me what is the mistake in my code?
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
clc
sss=[];
for ii=1:20
filename=['sdd' num2str(ii) ,'.xls']
xx=exist(filename,'file');
if xx==0
continue
else
xlfile=['sdd' num2str(ii)]
arr=xlsread(xlfile);
sss=[sss double(arr(:,1))]
[C,I] = min(sss);
end
end
the errors are:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in Test (line 21)
sss=[sss double(arr(:,1))]
Réponses (1)
Take a look at the dimensions of 'arr' after the line:
arr=xlsread(xlfile);
and compare it to sss.
If at some iteration you get a different number of values in arr(:,1) then you will not be able to concatenate it.
Every time round the loop you must have the same length of column vector there in order to concatenate.
We don't have your data though so can't repeat the problem other than by guessing what arr might be.
If you expect that your arr(:,1) will be of different lengths for different files then you will probably need to use a cell array for sss instead.
2 commentaires
Anass Masri
le 10 Fév 2015
Adam
le 10 Fév 2015
You can start with:
sss = cell.empty;
then in your for loop use the following code:
sss = [sss { double(arr(:,1)) }];
in place of your current
sss=[sss double(arr(:,1))];
and that should give you a cell array which you can then extract columns of as e.g
sss{2}
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!