How to save images using for loop?

조회 수: 1 (최근 30일)
Nisreen Sulayman
Nisreen Sulayman 2014년 9월 18일
댓글: Nisreen Sulayman 2014년 9월 18일
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 ??

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 9월 18일
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
Nisreen Sulayman
Nisreen Sulayman 2014년 9월 18일
That was very helpful, Thank you

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

추가 답변 (1개)

Roger Wohlwend
Roger Wohlwend 2014년 9월 18일
편집: Roger Wohlwend 2014년 9월 18일
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.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by