Locate max by clicking on 2D surface
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!