필터 지우기
필터 지우기

How do you dynamically generate file names?

조회 수: 5 (최근 30일)
Jorge
Jorge 2011년 2월 2일
Hi. I try save a graphic as a image (jpg). I've written:
%--------------------------------
m=cell(5,1)
m(1,1)={'A'}
m(2,1)={'B'}
m(3,1)={'C'}
m(4,1)={'D'}
m(5,1)={'E'}
for j=1:5
x=plot(rand(j))
saveas(gcf,'image_m(j,1).jpg')
end
%-------------------------------------
I wrote m(j,1) because I want obtain those files:
image_A.jpg
image_B.jpg
image_C.jpg
image_D.jpg
image_E.jpg
-------------------------
I wrote m(j,1), although I know that it is wrong.
Any ideas? Thanks in advance

채택된 답변

Jiro Doke
Jiro Doke 2011년 2월 2일
I suggest rephrasing the title to "How to dynamically generate file names", which is similar to this question.
Here's a short example demonstrating how you can do this:
suffixes = {'one', 'two', 'three', 'four', 'five'};
for j = 1:5
plot(rand(10,3));
saveas(gcf, ['image_', suffixes{j}, '.jpg']);
end
  댓글 수: 2
Jorge
Jorge 2011년 2월 2일
Thank you very much Jiro!
Yahia chs
Yahia chs 2011년 5월 19일
Thank you a lot
This was really helpful

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

추가 답변 (1개)

Jorge
Jorge 2011년 2월 3일
How I can do to get this?:
image_house.jpg
image_dog.jpg
image_car.jpg
I try do it with a cell array but I can't.
Thanks
  댓글 수: 1
Jiro Doke
Jiro Doke 2011년 2월 3일
I updated my answer above. Please rename the title of your question to "How do you dynamically generate file names?"

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by