why do I get this error? Indexing

2 Ansichten (letzte 30 Tage)
flashpode
flashpode am 22 Okt. 2021
Kommentiert: flashpode am 22 Okt. 2021
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

Antworten (1)

Steven Lord
Steven Lord am 22 Okt. 2021
I'm guessing you have:
A = duration([1; 2; 3; 4], [5; 6; 7; 8], [9; 10; 11; 12])
A = 4×1 duration array
01:05:09 02:06:10 03:07:11 04:08:12
C = {'03:07:11'; '01:06:12'}
C = 2×1 cell array
{'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)
Cdur = 2×1 duration array
03:07:11 01:06:12
[isCInA, whereIsCInA] = ismember(Cdur, A)
isCInA = 2×1 logical array
1 0
whereIsCInA = 2×1
3 0
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.
  1 Kommentar
flashpode
flashpode am 22 Okt. 2021
Hi, no my Tme_msg_match gives me the position from the time like
A = duration([1; 2; 3; 4], [5; 6; 7; 8], [9; 10; 11; 12])
C = cell{'2','3'} second and third line
and my out put I would like is tho get
D = duration([5; 6; 7; 8], [9; 10; 11; 12])

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by