How can I save each images in a loop for?

4 visualizzazioni (ultimi 30 giorni)
Felicia DE CAPUA
Felicia DE CAPUA il 8 Feb 2023
Commentato: Walter Roberson il 16 Feb 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 Commento
Vilém Frynta
Vilém Frynta il 8 Feb 2023
Modificato: Vilém Frynta il 8 Feb 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

Accedi per commentare.

Risposte (1)

Dongyue
Dongyue il 16 Feb 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 Commento
Walter Roberson
Walter Roberson il 16 Feb 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.

Accedi per commentare.

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by