フィルターのクリア

How to store every iteration of while loop into array?

2 ビュー (過去 30 日間)
Riley Morris
Riley Morris 2023 年 1 月 31 日
回答済み: Tushar Behera 2023 年 1 月 31 日
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!

採用された回答

Tushar Behera
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 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by