how to plot points in a GUI
古いコメントを表示
I have a Gui that I am trying to plot random points in but everytime I plot something it erases the button I have made in the GUi and the point doesnt show up on the graph portion. how do i fix this issue?
7 件のコメント
Image Analyst
2022 年 11 月 10 日
Attach your files (.mlapp file if using App Designer or .m and .fig files if using GUIDE) with the paperclip icon after you read this:
Learn App Designer here:
Voss
2022 年 11 月 10 日
@Amanda: It appears you are creating your GUI programmatically (without using AppDesigner or GUIDE), using code as follows (copied from here):
f= figure;
ax= axes('Parent',f,'Position',[0.05, 0.25, 0.9, 0.7]);
hold on;
my_button = uicontrol('style','pushbutton');
set(my_button, 'units', 'normalized', 'position', [0.05,0.05,0.3,0.15])
set(my_button, 'string','Add Point')
my_second_button = uicontrol('style','pushbutton');
set(my_second_button, 'units', 'normalized', 'position', [0.35,0.05,0.3,0.15])
set(my_second_button, 'string', 'Clear')
my_third_button = uicontrol('style', 'pushbutton');
set(my_third_button, 'units', 'normalized','position', [0.65,0.05,0.3,0.15])
set(my_third_button, 'string', 'Randomize')
Can you share the code you're using to plot the random points?
And also please attach some screen shots. In particular, include a screen shot of how the figure window looks after the buttons are "erased".
Amanda
2022 年 11 月 11 日
Amanda
2022 年 11 月 11 日
Not sure why the buttons appear to go away. They persist when I run the code here. (I've added a data marker in the plot call so that the single point shows up.)
f= figure;
ax= axes('Parent',f,'Position',[0.05, 0.25, 0.9, 0.7]);
x = 0.25;
y = 0.6;
plot(x,y,'.');
hold on;
my_button = uicontrol('style','pushbutton');
set(my_button, 'units', 'normalized', 'position', [0.05,0.05,0.3,0.15])
set(my_button, 'string','Add Point')
my_second_button = uicontrol('style','pushbutton');
set(my_second_button, 'units', 'normalized', 'position', [0.35,0.05,0.3,0.15])
set(my_second_button, 'string', 'Clear')
my_third_button = uicontrol('style', 'pushbutton');
set(my_third_button, 'units', 'normalized','position', [0.65,0.05,0.3,0.15])
set(my_third_button, 'string', 'Randomize')
Can you run the following line after running your script (or add it to the end of your script), and see if it returns 1 or 0?
ishandle(my_button)
Voss
2022 年 11 月 11 日
Also, the fact that your axes still has default x- and y-limits ([0 1]) makes me think your script is plotting into another axes somehow and/or the buttons are being created in another figure somehow.
Rik
2022 年 11 月 11 日
Why did you post your code as an image? Now anyone who wants to run your code will have to type it. Please replace the image with your code.
Also, when using GUIs, you should always use explicit handles when using functions like plot. That way you ensure that plots will appear where you expect them.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


