Filter löschen
Filter löschen

How to store every iteration of while loop into array?

1 Ansicht (letzte 30 Tage)
Riley Morris
Riley Morris am 31 Jan. 2023
Beantwortet: Tushar Behera am 31 Jan. 2023
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!

Akzeptierte Antwort

Tushar Behera
Tushar Behera am 31 Jan. 2023
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

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by