I just want to iterate through an image array one by one but I can’t get it working, I get the errors below. I can show single images via imshow (a), but not iterate through an array.
Error using getImageFromFile (line 12)
Cannot find the specified file: “a”.
Error in imageDisplayParseInputs (line 74)
[common_args.CData,common_args.Map] = …
Error in imshow (line 198)
[common_args,specific_args] = …
Code
% Images
a = 'redsquare.bmp';
b = 'bluesquare.bmp';
c = 'greysquare.bmp';
d = 'yellowsquare.bmp';
% Array to display
t = [a b c d];
% Loop to display
for n=1:length(t)
imshow(t(n))
end
Thanks.
You have several bugs in the code as it is.
First, verify that the directory where the images are located is in Matlab’s path , or try adding the full path of the images locations.
I’d recommend to use a cell array to contain all the file names. The way you’ve done it in the question is to concatenate all strings to one long one, that is
So in the code change
tto:In the loop, you need first to read the image to an array before showing it, therefor add an
imreadline. After reading the file onto an array (lets called that arrayim), you can useimshowto plot it. All in all, the code in the loop should be:Again, note that I used curly brackets
{}for theimreadline, that is the way to extract the cell element content.