Find corresponding dates in a calendar
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ali Akbar
el 20 de Abr. de 2015
Comentada: Ali Akbar
el 21 de Abr. de 2015
I have dates in a variable "calendar":
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149254/image.png)
I have another variable with certain dates "ISM_krock" which I want to use to extract the corresponding row number from "calendar":
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149256/image.png)
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 comentarios
Respuesta aceptada
pfb
el 20 de Abr. de 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".
Más respuestas (0)
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!