You are on page 1of 5

1.

Write a Matlab program to determine the location of peak in the following elevation data
stored in a data file.
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35]

Solution
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35];
save elevation.dat A-ascii
Load elevation.dat
[r,c] = size (elevation)
for m = 2 : r-1
for n = 2: c-1
if ( elevation (m,n) > elevation (m,n-1) &…
elevation (m,n) > elevation (m-1,n) &…
elevation (m,n) > elevation (m,n+1) &…
elevation (m,n) > elevation (m+1,n) )
fprintf (‘location of peak at (%6.0f, %6.0f) \n’, m,n)
end
end
end
2. Write a Matlab program to determine the number and location of the peaks in the following
elevation data stored in a data file.
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35]

Solution
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35];
save elevation.dat A-ascii
Load elevation.dat
[r,c] = size (elevation)
for m = 2 : r-1
for n = 2: c-1
if ( elevation (m,n) > elevation (m,n-1) &---
elevation (m,n) > elevation (m-1,n) &---
elevation (m,n) > elevation (m,n+1) &---
elevation (m,n) > elevation (m+1,n) )
count = count+1
end
end
end
fprintf (‘number of peak at %6.0f) \n’, count)
fprintf (‘location of peak at (%6.0f, %6.0f) \n’, m,n)

3. Write a Matlab program to determine the number of the peak in the following elevation data
stored in a data file.
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35]

Solution
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35];
save elevation.dat A-ascii
Load elevation.dat
[r,c] = size (elevation)
for m = 2 : r-1
for n = 2: c-1
if ( elevation (m,n) > elevation (m,n-1) &---
elevation (m,n) > elevation (m-1,n) &---
elevation (m,n) > elevation (m,n+1) &---
elevation (m,n) > elevation (m+1,n) )
count = count+1
end
end
end
fprintf (‘number of peak at %6.0f) \n’, count)
4. Write a Matlab program to determine the location of elevation where elevation point lower
than the elevation of four neighboring points.
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35]

Solution
A = [ 25 59 63 23 21 34 21 50
32 45 43 30 37 32 30 27
34 38 38 39 36 28 28 35
40 45 42 48 32 30 27 25
39 39 40 42 48 49 25 30
31 31 31 32 32 33 44 35];
save elevation.dat A-ascii
Load elevation.dat
[r,c] = size (elevation)
for m = 2 : r-1
for n = 2: c-1
if ( elevation (m,n) < elevation (m,n-1) &---
elevation (m,n) < elevation (m-1,n) &---
elevation (m,n) < elevation (m,n+1) &---
elevation (m,n) < elevation (m+1,n) )
fprintf (‘location of elevation at (%6.0f, %6.0f)) \n’, m,n)
end
end
end

You might also like