How can I save each images in a loop for?

조회 수: 1 (최근 30일)
Felicia DE CAPUA
Felicia DE CAPUA 2023년 2월 8일
댓글: Walter Roberson 2023년 2월 16일
Hi everyone,
I need to save each images product in a ciclo for. How can I do this?
When I tried to do it, it appears:
"Error using plot_matrix
Too many output arguments."
Do you have any advices?
  댓글 수: 1
Vilém Frynta
Vilém Frynta 2023년 2월 8일
편집: Vilém Frynta 2023년 2월 8일
It would be helpful to see your code, so we can help you better.
Without seeing your code, I can advise you to to create strings that change in each loop and then use these strings as new names to save images.
Something like...
for q = 1:10
name = strcat("img",num2str(q)) % create name; results will be img1, img2,..
plot(x(q),y(q)) % plot your things
print(gcf,name,'-dpng','-r300'); % save plot (or use imwrite if it's an image)
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Dongyue
Dongyue 2023년 2월 16일
clear; close all; clc;
for i = 1:5
img_name = ['img',num2str(i),'.jpg'];
img = rand(25,25,3);
imwrite(img,img_name)
end
You can go through the documentation for imwrite() for more information about saving images:
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 2월 16일
I would probably code either
img_name = sprintf('img%d.jpg', i);
or else
img_name = "img" + i + ".jpg";
When you use double-quoted strings and the + operator then the number in i (and up to 4 decimal places) will be converted to text automatically without needing to explicitly convert the number.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by