필터 지우기
필터 지우기

Why do I get subscript indices error?

조회 수: 1 (최근 30일)
Sherwin
Sherwin 2016년 10월 28일
댓글: Walter Roberson 2016년 10월 29일
Hi, I have a code like this,
r2 = randi([2 64]);
[m, n] = ind2sub([4 16],r2);
n = (n-1)*60;
CH1(m:end,n:end) = P2(m:end,n:end);
CH1 and P2 are two matrices. I generated 'r2' randomly and used 'ind2sub' to find the indices of the element r2. So I expected m and n to be numbers, but I get this error:
??? Subscript indices must either be real positive integers or
logicals.
Please help.

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 28일
r2 = 2:4;
[m, n] = ind2sub([4 16],r2)
(n-1)*60
  댓글 수: 8
Walter Roberson
Walter Roberson 2016년 10월 28일
You should use the debugger
dbstop if error
and run. When it stops, tell us what the values of r and c and r3(i) are
Walter Roberson
Walter Roberson 2016년 10월 29일
You asked this later question at http://www.mathworks.com/matlabcentral/answers/309643-why-do-i-get-an-index-error and it was answered there.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by