Getting error as array indices must be positive integers or logical values in slope calculation.
조회 수: 1 (최근 30일)
이전 댓글 표시
My R matrix is 512x43 and I would like to calculate slope by central diff from row wise values.
It shows logical values error ? What's the wrong in this slope calculation.
Thanks in advance.
%testing slope by central difference
load('R.mat');
dy = zeros(43,1);
ddy = zeros(43,1);
delx = 1e-4;
for ij=1:1:512
for ji = 1:1:43
dy(ij,ji) = (R(ij,ji+1)-R(ij,ji-1))/(2/delx);
ddy(ij,ji) = (R(ij,ji+1)-2*R(ij,ji)+R(ij,ji-1))/delx^2;
end
end
댓글 수: 2
채택된 답변
Cris LaPierre
2021년 9월 15일
편집: Cris LaPierre
2021년 9월 15일
I suspect the error is in your column index for R:
- ji-1
When ji=1, the result is 0, which is not a valid index in MATLAB.
Note that you will have another problem when hi=43, as you also use ji+1. The result will be 44, which exceeds the size of R.
댓글 수: 5
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!