Store Data Using a for Loop
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Hi,
For each year in a ten year period:
*Location = storage space 1:652 made earlier in the script
*day_of_year = column vector of 652 dates
I have a column vector of 652 dates for each year, day_of_year. I could like to store these in my empty 652 zero vector Location. I would then like to store each year vector with the correct year before moving onto the next year to process. When I try what I have below I get Assignment has more non-singleton rhs dimensions than non-singleton subscripts
I don't know how to fix this, or what this means, can anybody offer any help or point me in the right direction?
for Date = 1:652
Location(Date) = day_of_year(Date);
Real_Date = datestr(Location)
% FirstDate(Date) = Real_Date(Date)
end
% Store Data
Date_For_Year(year,:) = Real_Date_
Thank you!
4 个评论
Eric Pahlke
2015-7-17
Please either post examples of all the matrices so I can run the code, or check size() of each of the arrays. I created day_of_year and Location arrays per the sizes you talked about and didn't have any errors in the code (although it runs slowly because you're doing datestr on the whole array every time through the loop). How are the dates stored in day_of_year? Dates can either be decimal (datenum()), string, or I believe there is an YY:MM:DD:HH:MM:SS format that stores dates as a vector, in which case day_of_year may be 652x6 rather than 652x1.
Star Strider
2015-7-17
This is an essential duplicate of: http://www.mathworks.com/matlabcentral/answers/230234-how-to-store-data-in-a-for-loop.
I deleted one other duplicate, but I must not have seen all of them.
Chameleon17
2015-7-17
Star Strider
2015-7-17
No worries. It’s best not to post multiple entries to clarify what you want. That’s what the ‘Edit’ function is for. Edit at will, but it’s courteous to mention at the end of your post something like:
EDIT: Changed matrix dimensions
EDIT #2: Uploaded file
or some such, as necessary, otherwise we won’t know what the edits were.
回答(0 个)
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!