Finiding Peaks and plotting in 3D

10 views (last 30 days)
Kondiik
Kondiik on 4 Nov 2013
Edited: A Jenkins on 4 Nov 2013
Hello everyone I have two problems with my project first is: 1) how i can plot tx, ty and tz? 2) I have to find peaks (I wrote program which check values in matrix 49x49. if "o" value is greater 8 times than all numbers around then that's the peak. Loop unfortunately doesn't work and I can't find a mistake
1 2 3
47 x x x
48 x o x
49 x x x
My program
%generate a reasonable terrain from a function
tx =linspace(-30, 30, 49*49);
ty = tx;
[xx, yy] = meshgrid(tx, ty);
tz = % I didnt paste it here because data from .m file contain 2401 values.
figure(1);
mesh(tx, ty, tz);
figure(2);
contour(xx, yy, tz);
for row = 2:48
for column = 2:48
p_c = 0;
t_c = 0;
for n = row - 1:row + 1
for m = column - 1:column + 1
if(tz(row, column) > tz(n, m))
p_c = p_c+1;
elseif(tz(row, column) < tz(n, m))
t_c = t_c+1;
end
end
end
if(p_c > 7)
disp( sprintf( 'Peak found at row %d column %d', row, column));
elseif(t_c > 7)
disp( sprintf( 'Trough found at row %d column %d', row, column));
end
end
end
  4 Comments
Image Analyst
Image Analyst on 4 Nov 2013
Can you use imreagionalmax() in the Image Processing Toolbox?
Kondiik
Kondiik on 4 Nov 2013
Edited: Kondiik on 4 Nov 2013
no I have to find it almost "by hand". That's the problem. Last chapter was loops and this one is 3D plotting so he wants use us bothchapters, not ready function in matlab. That's is why I thing many ppl will fail this class.

Sign in to comment.

Answers (1)

A Jenkins
A Jenkins on 4 Nov 2013
Edited: A Jenkins on 4 Nov 2013
I ran your code and it works fine for me as long as I change the first line from
tx =linspace(-30, 30, 49*49);
to
tx =linspace(-30, 30, 49);
_____________________________________________________________________
I get the following:
Trough found at row 12 column 27
Peak found at row 20 column 21
Peak found at row 25 column 35
Trough found at row 27 column 14
Trough found at row 28 column 27
Peak found at row 38 column 25
These match what I see in the figures generated.
_____________________________________________________________________
(Though you might want to print out the values of tx(row) and ty(column) instead of just row and column, so it matches the indicies on your plots.)
Trough found at x=-16.250 y=2.500
Peak found at x=-6.250 y=-5.000
Peak found at x=0.000 y=12.500
Trough found at x=2.500 y=-13.750
Trough found at x=3.750 y=2.500
Peak found at x=16.250 y=0.000

Community Treasure Hunt

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

Start Hunting!