필터 지우기
필터 지우기

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 CenterFile Exchange에서 Resizing 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