フィルターのクリア

Help writing a function for a gui

2 ビュー (過去 30 日間)
Amanda
Amanda 2022 年 11 月 29 日
回答済み: David Hill 2022 年 11 月 29 日
I have created a GUI with a graph that randomly plots a point on the graph. I have a push button that when its clicked I want it to be able to add another random point with a different marker shape/size/color. I need to write a function to do this but i'm unsure how to do so.
  2 件のコメント
David Hill
David Hill 2022 年 11 月 29 日
Put your code in a code box or attach. Make it easy for us to help you.
Amanda
Amanda 2022 年 11 月 29 日
f= figure;
ax= axes('Parent',f,'Position',[0.05, 0.25, 0.9, 0.7]);
xlim = ([0,1]);
ylim = ([0,1]);
x = 0.25;
y = 0.55;
point_plot_handle = plot(x,y,'d','MarkerFaceColor','m','MarkerSize',75);
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')
set(my_button, 'callback', '@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')
set(my_second_button, 'callback', @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')
set(my_third_button, 'callback', {@randomize,point_plot_handle});
function randomize(sender, eventdata, h)
new_point = randn(2,1);
set(h,'XData', new_point(1), 'YData', new_point(2));
end
function clear(sender, eventdata)
empty = cla;
end

サインインしてコメントする。

採用された回答

David Hill
David Hill 2022 年 11 月 29 日
Not sure what you want the randomize function to do.
f= figure;
axes('Parent',f,'Position',[0.05, 0.25, 0.9, 0.7]);
x = 0.25;
y = 0.55;
plot(x,y,'d','MarkerFaceColor','m','MarkerSize',35);
hold on;
ax=gca;
ax.XLim=[0 1];
ax.YLim=[0 1];
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')
set(my_button, 'callback', @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')
set(my_second_button, 'callback', @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')
set(my_third_button, 'callback', @randomize);
function randomize(sender, eventdata, h)
new_point = randn(2,1);
set(h,'XData', new_point(1), 'YData', new_point(2));
end
function clear(~,~)
cla;
end
function add_point(~,~)
l='osdph><v^';
plot(rand,rand,l(randi(9)),'MarkerFaceColor',rand(1,3),'MarkerSize',35);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by