Index exceeds the number of array elements (1). How can I correct this error?

조회 수: 2 (최근 30일)
flashpode
flashpode 2021년 10월 26일
댓글: flashpode 2021년 10월 26일
Hi I've got this code that gives me the messages from a variable that are from a mmsi that I want
Msg_mmsi_selected = [];
for i=1:1:L
seq1 = msg_NoMatchAIS1(i);
linia=convertStringsToChars(seq1);
if linia(13)=='A' && linia(15)=='1'
sequencia = ais_to_bit(linia(15:44));
s_mmsi=sequencia(9:38);
mmsi= bin2dec(num2str(s_mmsi));
Msg_mmsi_selected = seq1(mmsi_selected); % Here is the line that give me error
end
end
and the error I got is
Index exceeds the number of array elements (1).
Is there any problem in the line code that makes me this error. I thought it was because of not named the variable but I did and do not know why I continue having it.
  댓글 수: 3
DGM
DGM 2021년 10월 26일
There's not enough information to answer the question. The index mmsi_selected exceeds the number of elements in seq1, but nobody knows what either of these two variables are (their value or size) or how they are created.
Try to provide enough context such that the problem can be reproduced.
flashpode
flashpode 2021년 10월 26일
well I am gonna changa the question due to a change of code. That maybe it is easy for me to explain. Lets see, I've got a variable that is num_mmsi_selected that has the number of the mmsi in the position that we find it. So my question is how can I change the number of the mmsi to the number of the cell with find it. Now a example:
Here we can see that in the cells 5 and 6 there is the mmsi so I want to change this number and put 5 and 6 the same with all the lines that have this number. I uploaded the data so you can work easily.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by