MATLAB Answers

how to use nested for loop by grabbing one column and subtracting another column.

조회 수: 3(최근 30일)
tonyrodriguez
tonyrodriguez 29 Mar 2018
Edited: Roger Stafford 29 Mar 2018
so i have this huge file that is 1478 by 1236 matrix and i want to calculate the xslope and yslope as follows

  댓글 수: 1

tonyrodriguez
tonyrodriguez 29 Mar 2018
so far i have this
cellsize = 9.47733915533982;
xslope = zeros(1478,1236);
n = length(xslope);
for i = 1:n for j = 1:1:n
xslope(i,j) = ( z(i,j+1)-z(i,j) )/cellsize;
end
end
xslope
it tells me i have a matrix dismension.. can someone help me fix this or tell me how i can do it?

로그인 to comment.

답변 수 (1)

Roger Stafford
Roger Stafford 29 Mar 2018
Roger Stafford 님이 편집함. 29 Mar 2018
Your n value will be 1478, but in z(i,j+1) you have allowed the j+1 index to get as large as 1479 because you have "for j=1:1:n" and its maximum value should be only 1236. Hence the error message. You need to do
[n,m] = size(z)
and
for j = 1:m-1

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by