Find corresponding dates in a calendar
2 次查看(过去 30 天)
显示 更早的评论
I have dates in a variable "calendar":
I have another variable with certain dates "ISM_krock" which I want to use to extract the corresponding row number from "calendar":
If I use simply
r=calendar(ISM_krock);
it will return: Subscript indices must either be real positive integers or logicals.
How do I solve this?
0 个评论
采纳的回答
pfb
2015-4-20
The error you get is self explaining, I think. ISM_krock contains many zeros (apparently columns 4 to 6 entirely consist of zeros). An index cannot be a (non-logical) zero. Just a positive integer or a logical.
You should explain better what you want to do. I'm not sure I understand.
If you want to find the index in calendar for one date (e.g. the jth) in ISM_krock , you should compare that date to all those in calendar, using "==". For instance
i = find((calendar(:,1)==ISM_krock(j,1)) & (calendar(:,2)==ISM_krock(j,2)) & (calendar(:,3)==ISM_krock(j,3)));
I'm using just the first 3 columns because I'm not sure of the meaning of all those zeros. I guess the dates are just the firse 3 columns.
If you want to do that for all the dates in ISM_krock, I'm afraid you need to iterate the above comparison over all the rows in ISM_krock. I do not see a way of doing this in a simple "one-liner". But perhaps someone in this forum will prove me wrong.
Another suggestion. It would be more useful to attach the variables themselves (in a *.mat file) instead of their "screenshot".
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!