Filter löschen
Filter löschen

Get correct positions on gui to draw lines between pushbuttons GUIDE

2 Ansichten (letzte 30 Tage)
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!

Antworten (1)

Walter Roberson
Walter Roberson am 26 Mai 2019
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

Kategorien

Mehr zu Migrate GUIDE Apps 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!

Translated by