Get correct positions on gui to draw lines between pushbuttons GUIDE

2 次查看(过去 30 天)
Hi everyone!
I am having trouble using the positions parameter of my matlab gui. I have cretaed a gui with several pushbuttons and I have put an image as background of the gui. Whenever a pushbutton is pressed the position of the pushbutton is saved and when the ok button is pressed lines between pushbutton should be drawn. Here is where I am stuck, I cant find a solution.
To get every pushbutton position I use:
pos = get(hObject, 'Position');
The code I use when pressing the ok button is this (handles.positions has the x and y coordinates of every pushbutton pressed):
[m n] = size(handles.positions);
x = handles.positions(:,1);
y = handles.positions(:,2);
x = x';
y= y';
axes
ah = axes('unit', 'normalized', 'position', [0 0 1 1]);
imagesc(handles.bg);
hold on
line(x,y)
handles.i = 0
guidata(hObject, handles);
If someone knows how to solve this it would be great. Thanks to all!

回答(1 个)

Walter Roberson
Walter Roberson 2019-5-26
The Position of a uicontrol is never axes data coordinates such as is needed to draw on the image.
axes
ah = axes('unit', 'normalized', 'position', [0 0 1 1]);
imagesc(handles.bg);
You are creating two new axes there, and then when you draw the image, it is not certain that it will be drawn in either of those two. See https://www.mathworks.com/matlabcentral/answers/?term=tag%3Aalways-parent

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by