How to save images using for loop?

2 vues (au cours des 30 derniers jours)
Nisreen Sulayman
Nisreen Sulayman le 18 Sep 2014
I have an error using imwrite:
names={'Adel1','Adel2','Adel3'}% Cell array contains images' names
for i = 1 : length(names)
imwrite(Seg{i},['E:\Aneurysms\Images\names(i)_seg','.tif'])
% seg: segmentation function result
end
the previous code save only the last variable with the name: names(i)_seg
I want to save new images like: Adel1_seg, Adel2_seg,Adel3_seg
what is wrong in using imwrite ??

Réponse acceptée

Michael Haderlein
Michael Haderlein le 18 Sep 2014
There's nothing wrong using imwrite, there's something wrong how you create the file name. Just use
['E:\Aneurysms\Images\' names{i} '_seg.tif']
  1 commentaire
Nisreen Sulayman
Nisreen Sulayman le 18 Sep 2014
That was very helpful, Thank you

Connectez-vous pour commenter.

Plus de réponses (1)

Roger Wohlwend
Roger Wohlwend le 18 Sep 2014
Modifié(e) : Roger Wohlwend le 18 Sep 2014
The function imwrite does exactly what you told it to do. The problem is that
['E:\Aneurysms\Images\names(i)_seg','.tif']
gives you a static text. It does not do what you want it to do. Replace it with the following code:
['E:\Aneurysms\Images\', names{i}, '_seg.tif']
That should solve your problem.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by