Filter löschen
Filter löschen

Find corresponding dates in a calendar

2 Ansichten (letzte 30 Tage)
Ali Akbar
Ali Akbar am 20 Apr. 2015
Kommentiert: Ali Akbar am 21 Apr. 2015
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?

Akzeptierte Antwort

pfb
pfb am 20 Apr. 2015
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 Kommentar
Ali Akbar
Ali Akbar am 21 Apr. 2015
Your code together with a loop makes the iteration much more simple. Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by