Reputation: 888
I have 15 images that I am reading using imagedata = imread('imagename.jpg')
its size is always 320 by 320 by 3
How do I put the data in an array (using a for for loop) such that when I access the first element of the new array I get the RGB data of the first image I input?
Upvotes: 2
Views: 54
Reputation: 112669
Since all images have the same size, it may be more efficient to use a 4D array than a cell array:
imArray = NaN(320,320,3,15);
for n = 1:15
imArray(:,:,:,n) = imread(filename); %// filename should probably change
end
You can then access the first image as imArray(:,:,:,1)
, etc.
Upvotes: 2
Reputation: 4336
You should probably use cell
imCell = {};
for i = 1 :15
imCell{i} = imread(num2str(something));
end
And you could easily have access,
for j = 1 : 15
subplot(5,3,j);
imshow(imCell{j});
end
imCell
is a cell with size 1x15
. However imCell{i}
is an arrey with size 320x320x3
.
Using cell will allow you to even save arrays of different sizes in it.
Upvotes: 3