Get max or min value from a mesh plot interactively?

조회 수: 3 (최근 30일)
Juan Vences
Juan Vences 2021년 8월 2일
댓글: Juan Vences 2021년 8월 4일
Hello everybody,
It's been a while since last time I used Matlab (lol), and any help would be highly appreciated :)
Currently I'm figuring out ways to get max or min values from a figure like the one attached in this post
Ideally it would be great to get the max and min with an interactive "selection window" (example is from a screenshot from Paint with the "desired concept").
The figure is a "mesh surface" with "colormap(jet)" and color bar as shown in the screenshot (attached).
Any ideas guys?
Many thanks!
  댓글 수: 1
Juan Vences
Juan Vences 2021년 8월 2일
Forgot to mention this detail:
Get "x", "y" corresponding to that max or min "z" value

댓글을 달려면 로그인하십시오.

채택된 답변

Dave B
Dave B 2021년 8월 2일
Without implementing something to draw the rectangle and display the result, you can get this with an extra step or two using brushing:
mesh(peaks, 'FaceColor', 'flat')
view(2)
brush %or click the icon that looks like a paintbrush in the upper right corner of the axes
click and drag to select a region, it will show up as red
right click and choose 'Export brushed'
Choose a variable name or use the default, now the data is available in the command window
max(brushed_data(:))
  댓글 수: 3
Dave B
Dave B 2021년 8월 3일
@Juan Vences as a general rule this kind of indexing work is no problem for MATLAB:
If you're data are already 3 matrices (I forget what brushing will give you):
[maxVal,maxInd]=max(z(:));
x(maxInd)
y(maxInd)
sprintf('A maximum value of %0.2f was reached at x=%0.2f, y=%0.2f', x, y, maxVal)
If x and y are vectors, and you want to turn them into matrices that match the size of z:
[xi, yi]=meshgrid(x, y);
For what it's worth, I also liked @Image Analyst's drawrectangle solution. It may offer a more extensible solution (if you already have image processing toolbox)!
Juan Vences
Juan Vences 2021년 8월 4일
Thank you @Dave B
Yes, this is totally an index stuff and shouldn't be a big deal for Matlab... is more a big deal for me... '^_^
Thank you for your answer

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 8월 2일
편집: Image Analyst 2021년 8월 2일
Since it looks like an image, I believe you can use drawrectangle() and then just use min and max on the sub-image you get by indexing.
rgbImage = imread('cameraman.tif');
subplot(1, 2, 1);
imshow(rgbImage, 'Colormap', hsv(256));
g = gcf;
g.WindowState = 'maximized';
colorbar
axis on;
uiwait(helpdlg('Drag out a rectangle'));
roi = drawrectangle()
p = round(roi.Position)
subImage = imcrop(rgbImage, p);
subplot(1, 2, 2);
imshow(subImage);
axis on;
meanValue = mean2(subImage)
minValue = min(subImage(:))
maxValue = max(subImage(:))
message = sprintf('The Mean Gray Level is %f', meanValue);
title(message, 'FontSize', 20);
uiwait(helpdlg(message));
  댓글 수: 1
Juan Vences
Juan Vences 2021년 8월 4일
Thank you so much @Image Analyst !
I think this one is real nice and elegant option, it is so good that I am not at its level '^_^
Hope to use one day
However, it is correct that my doubt is so simply that doesn't not deserve such a high quality answer. But I highty appreciate your time!
Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by