How can I save each images in a loop for?

3 visualizaciones (últimos 30 días)
Felicia DE CAPUA
Felicia DE CAPUA el 8 de Feb. de 2023
Comentada: Walter Roberson el 16 de Feb. de 2023
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 comentario
Vilém Frynta
Vilém Frynta el 8 de Feb. de 2023
Editada: Vilém Frynta el 8 de Feb. de 2023
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

Iniciar sesión para comentar.

Respuestas (1)

Dongyue
Dongyue el 16 de Feb. de 2023
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 comentario
Walter Roberson
Walter Roberson el 16 de Feb. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by