saving data when looping
1 次查看(过去 30 天)
显示 更早的评论
I am trying to save each data point in a table t while looping, but I always get the last data point which is 2012!
=![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/423928/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/423928/image.jpeg)
0 个评论
回答(1 个)
Mario Malic
2020-11-23
Because your t accepts only a scalar and it gets overwritten every single time.
% Before loop
n = 1;
t = zeros(1,length(1977:2012));
for i
t(n) = monthYear...
n = n + 1;
end
2 个评论
Mario Malic
2020-11-23
I haven't worked with timetable before. Probably, you need to initialise t as a timetable, and use dot indexing to change its values.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!