Get correct positions on gui to draw lines between pushbuttons GUIDE

2 ビュー (過去 30 日間)
Elena Martín
Elena Martín 2019 年 5 月 25 日
回答済み: Walter Roberson 2019 年 5 月 26 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by