why do I get this error? Indexing
2 views (last 30 days)
Show older comments
Hi, so I got those two variables:

Time_AIS1 is a duration variable that has many times. Times_msg_match has the lines from Time_AIS1 that I want. How can I get them without getting the problem of indexing. The message that I have is:
Unable to use a value of type cell as an index. I understand the problem but I do not get how to change to work correctly.
My code that generates Time_msg_match is:
Time_msg_match{K} = complete_match_AIS;
How could I change it to get the time directly? because I've change it the following way but I get another error:
Time_msg_match{K} = Time_AIS1(complete_match_AIS);
The error is the following: Cell contents assignment to a non-cell array.
Thank you in advance
0 Comments
Answers (1)
Steven Lord
on 22 Oct 2021
I'm guessing you have:
A = duration([1; 2; 3; 4], [5; 6; 7; 8], [9; 10; 11; 12])
C = {'03:07:11'; '01:06:12'}
You can't use C as an index into A. You can't even use A as an index into A. What you can do is to use ismember after converting C into a duration array.
Cdur = duration(C)
[isCInA, whereIsCInA] = ismember(Cdur, A)
Since the first element in whereIsCInA is 3, the first element of Cdur matches the third element of A. Since the second element of whereIsCInA is 0, the second element of Cdur is not present in A.
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!