How can I save each images in a loop for?

1 次查看(过去 30 天)
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