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!