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

1 Ansicht (letzte 30 Tage)
tonyrodriguez am 29 Mär. 2018
Bearbeitet: Roger Stafford am 29 Mär. 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
tonyrodriguez am 29 Mär. 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?

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Roger Stafford am 29 Mär. 2018
Bearbeitet: Roger Stafford am 29 Mär. 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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu ASK finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by