I want to save the data in for loop but it only gives me the last data. How can I accumulate the data in row?
----------------------------
Month ={'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};
m=[];
for year = 2000:2001
for month = 1:12
m=sprintf('%04d%s', year, Month{month});
end
end

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 21일

1 개 추천

m{end+1}=sprintf('%04d%s', year, Month{month});

댓글 수: 3

Bum
Bum 2013년 2월 21일
Thanks!! Would you please explain me how it works? What is 'end' and {}...?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 21일
편집: Azzi Abdelmalek 2013년 2월 21일
m is a cell array indicated by { }
help cell
if m=[ 1 2 5] then m(end)=5,
when you type m(end+1) it means m(3+1)
Bum
Bum 2013년 2월 21일
Thanks. Then why does it accumulates the output?

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

Bum
2013년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by