Locate max by clicking on 2D surface

조회 수: 1 (최근 30일)
Igor Arkhandeev
Igor Arkhandeev 2021년 4월 5일
댓글: Igor Arkhandeev 2021년 4월 5일
Hello! I try to write some siple code that should find and mark maximum in defining area. I have some code, but I don't understand. why marker is always righter than I click. I will be happy for any proposals.
close all;
f = figure;
s = surf(peaks);
view([0 90]);
shading interp;
GetMousePosition(f,'on');
s.ButtonDownFcn = @get_data_from_clicking;
function get_data_from_clicking(~, ~)
coords = get(gca, 'CurrentPoint');
[x,y] = get_xy(coords(1,1), coords(1,2));
[xx,yy] = find_maximum(x,y,peaks);
hold on;
scatter3(xx, yy, 10^4, 'filled');
end
function [xx,yy] = get_xy(x, y)
xx = floor(x);
dx = xx + 0.5;
if dx - x < 0; xx = dx; end
yy = floor(y);
end
function [xx,yy] = find_maximum(x,y,mat)
xx = 0; yy = 0;
x_start = 2*x - 1;
y_start = y - 2;
I = 0;
for i = 0:2
for j = 0:2
if mat(x_start + i, y_start + j) > I
xx = x_start + i;
yy = y_start + j;
I = mat(x_start + i, y_start + j);
end
end
end
end
  댓글 수: 1
Igor Arkhandeev
Igor Arkhandeev 2021년 4월 5일
I find that find_maximum function changing location of marker.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by