Reputation: 2229
I need to load many small grayscale images in MATLAB. All images are of the same type/size. How can I predefine an array and place a different image in each of its cell?
For example, an array of 100 images, inserting an image at position 50:
my_array = zeros(100);
...
my_array(50) = my_image;
...
imshow(my_array(50));
Thanks!
Upvotes: 0
Views: 293
Reputation: 846
You can do this using a cell array, simply define it as:
my_array = cell(100,1);
my_array{50} = my_image;
imshow(my_array{50})
Each cell of a cell array can hold different size arrays and types. I did assume that your my_image
variable was an array. Also notice the curly brackets, this is how you access/define the content in a cell array. Here is a small example:
a = rand(100); % 100x100 size array in cell position 1
r = rand(100,100,3); % Different size array in cell position 2
b = cell(2,1); % initialize cell
b{1} = a; % assign cell content
b{2} = r;
imshow(b{1})
The image is the results of imshow(b{1})
Upvotes: 1