Reputation: 47
I want to read multiple images which are in a folder in Scilab. My code is:
I1=dir('G:\SCI\FRAME\*.jpg');
n=length(I1);
disp(n);
for i=1:n
I2=strcat('G:\SCI\FRAME\',I1(i).name);
I=imread(I2);
figure(),imshow(I);
end
But it does not work. It shows error "invalid index".
Upvotes: 1
Views: 608
Reputation: 615
There are two mistakes to correct:
1.) length
gives the number of characters (=length) of a string, but you want to get the number of elements (=size) in a vector (the filenames), hence you should use size
.
2.) I1 is a list structure returned by dir
. You can extract its content with the .
operator, e.g. I1.name
, I1.date
, I1.bytes
, I1.isdir
. Type these into the consol, to see the contents! Since I1.name
already contains the fullpath+filename+extension as a string vector, you don't have to construct it with strcat
. Anyway if you want to "glue" 2 strings together, it's easier to use +
e.g. S="fisrst_string"+"second_string"
.
So the revised code:
I1=dir('G:\SCI\FRAME\*.jpg');
n=size(I1.name,"*"); //size of the I1.name vector
disp(n);
for i=1:n
I=imread(I1.name(i)); //I1.name is a string vector
figure();
imshow(I);
end
Upvotes: 1