Find corresponding dates in a calendar

조회 수: 1 (최근 30일)
Ali Akbar
Ali Akbar 2015년 4월 20일
댓글: Ali Akbar 2015년 4월 21일
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?

채택된 답변

pfb
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".
  댓글 수: 1
Ali Akbar
Ali Akbar 2015년 4월 21일
Your code together with a loop makes the iteration much more simple. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by