why do I get this error? Indexing
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Steven Lord
2021년 10월 22일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!