Can anybody tell me what is the mistake in my code?

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))]

Answers (1)

Adam
Adam on 10 Feb 2015
Edited: Adam on 10 Feb 2015
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 Comments

You are right, the length of column vector is different.
Can you please help me using cell array (find attached the data I'm using)?
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}

This question is closed.

Tags

Asked:

on 10 Feb 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!