How to store every iteration of while loop into array?
1 次查看(过去 30 天)
显示 更早的评论
favorite_image = imread('matlab project.jpg');
imshow(favorite_image)
sick=favorite_image
resize = favorite_image
counter={} %saving an empty array
while length(resize) > 32
resize = imresize(resize,1/2)
sick = resize
imshow(resize)
sick{counter+1} = resize %trying to store stuff in empty array
end
imshow(resize)
I am trying to put every single image from the resizing in the same array when I try to do it this way, it says that the operator is not supported for operand cell. What am I doing wrong? Thank you!
0 个评论
采纳的回答
Tushar Behera
2023-1-31
Hi Riley,
I believe what you are trying to do is create an cell array of images which adds on a new image in each iteration.
In the line
sick{counter+1} = resize %trying to store stuff in empty array
you are trying to add a numerical value to an empty cell type which is not allowed. In order to acheive what you are doing you can refer to the following psuedo code,
favorite_image = imread('image.jpg');
imshow(favorite_image)
resize = favorite_image
dummyresize=favorite_image
numimage=1;
while length(dummyresize) > 32
dummyresize = imresize(dummyresize,1/2)
numimage=numimage+1;
end
counter=cell(1,numimage) %creating a cell array of size number of images
a=1;
while length(resize) > 32
resize = imresize(resize,1/2)
sick = resize
imshow(resize)
counter{a} = resize %store stuff in cell array
a=a+1;
end
imshow(resize)
for i = 1:numimage
imshow(counter{i})%show all the image saved in counter
end
The above code keeps on adding the new image to the cell array counter.
I hope this solves your query.
Regards,
Tushar
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!