How to store data in a for loop?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm certain this is quite a basic and simple problem I'm having, but I've can't seem to figure it out.
I have data I'm processing for a series of years, for 652 locations for each year.
I made storage space at the start of my script so that I can store a date in each of the 652 locations at the end.
The script is done so that I am pulling out the dates I need for each year.
for Date = 1:652
Location(Date) = day_of_year(Date);
Real_Date = datestr(Location)
Result(Date) = Real_Date(Date)
end
P_Year(year,:) = Result
This is my latest attempt to to organize and store my data.
Location is my storage vector for the 652 locations, day_of_year is my results I want to store for each year.
It just doesn't seem to work. I would like to be able to store the results for each year in 652 sized vector and save each year separately. I might just be going round in circles and I know this is probably a very simple fix.
Any advice or direction to a video or something to read even would be very much appreciated.
Thank you
0 件のコメント
回答 (1 件)
Ghada Saleh
2015 年 7 月 20 日
Hello,
I understand that you want to convert the dates stored in 'day_of_year' to its string format and then store it in 'result'. In that case, you can do the following:
for Date = 1:652
Location = day_of_year(Date);
Real_Date = datestr(Location);
Result{Date} = Real_Date;
end
P_Year{year,:} = Result;
Note that 'Real_Date' is an array of strings (each character is stored as a separate element). So in order to copy each date as a single element in 'Result', you will need to define 'Result' as a cell array. To access the data in a cell array , you can use curly parenthesis.
I hope this helps,
Ghada
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!