how to save data in for loop?
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Azzi Abdelmalek
2013-2-21
m{end+1}=sprintf('%04d%s', year, Month{month});
3 个评论
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!