how to save data in for loop?

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

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 21 Feb. 2013

1 Stimme

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

3 Kommentare

Bum
Bum am 21 Feb. 2013
Thanks!! Would you please explain me how it works? What is 'end' and {}...?
Azzi Abdelmalek
Azzi Abdelmalek am 21 Feb. 2013
Bearbeitet: Azzi Abdelmalek am 21 Feb. 2013
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 am 21 Feb. 2013
Thanks. Then why does it accumulates the output?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by