Error using sub2ind Out of range subscript how to solve this?

조회 수: 9 (최근 30일)
Rabia Khan
Rabia Khan 2021년 5월 5일
답변: Steven Lord 2021년 5월 5일
indices= sub2ind(size(A_binary),(1:nb_tx_sensors_med),idx_selection);
here idx_selection=[6,9]
nb_tx_sensors_med=2
A_binary= 1x9
  댓글 수: 1
Rabia Khan
Rabia Khan 2021년 5월 5일
kindly help me out as i am unable to eliminate this error of out of range subscript.

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

답변 (1개)

Steven Lord
Steven Lord 2021년 5월 5일
What's the index of the value in row 1, column 6 of a 4-by-5 matrix?
sub2ind([4 5], 1, 6)
Error using sub2ind (line 55)
Out of range subscript.
Trick question, since a 4-by-5 matrix doesn't have a 6th column.
Your case is slightly different, since you're asking for indices into the second row of a matrix with only one row.
To solve this you need to figure out why your code is asking for an element in a row and/or a column that doesn't exist and make it either stop or ask for an element in a row and/or column that does exist in the matrix.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by