# Locate max by clicking on 2D surface

3 ビュー (過去 30 日間)
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]);
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 2021 年 4 月 5 日
I find that find_maximum function changing location of marker.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!