views:

46

answers:

1

Hi can somebody help me with the matlab command here. I've got to determine the highest point in a filled contour i've plotted using matrix data in a file. And then i have to mark the highest point with a red 'x'.

load('0101862_mod.dtm')   % loading the dtm file
X = X0101862_mod(1:81,:)  % we name X0101862, it is the location where the data X, Y and Z is stored
Y = X0101862_mod(82:162,:)
Z = X0101862_mod (163:243,:)

figure (1)
subplot(2,2,3)
[C,h] = contourf(X,Y,Z,10);
xlabel('x'); ylabel('y'); zlabel('z'); title('X0101862_mod');
view(-73,34); axis equal; colormap summer; colorbar;

i know it involves 'max' command. Kept getting error when i use max.

A: 

To plot the red 'X', you have to call first hold on to make sure that the second plotting command won't erase the contour. Then, you use plot(xMax,yMax,'xr') to plot a red 'x' at the x/y coordinates where z is at its maximum.

To find xMax and yMax, you have to use the second output argument of max. MAX returns, as first output, the maximum (e.g. of Z), and as a second output, it returns the number of the element that is maximal. Use that number (the index) to find the elements in X and Y that correspond to the maximum Z-value, i.e. xMax and yMax.

Jonas
is this correct?xMax = max(X); yMax = max(Y);plot(xMax,yMax, 'xr');
No. xMax is the X corresponding to the maximum Z. `[zMax,maxIdx] = max(Z);` returns, in `maxIdx` the location in the data vector where `Z` is highest. For example, if it is the 5th element in Z that is highest, `maxIdx` would be 5. Correspondingly, xMax would be the 5th element of `X`, and yMax the 5th element of `Y`.
Jonas

related questions