Replace buttons

8 次查看(过去 30 天)
Teresa
Teresa 2011-7-29
Hello,
I have a function which creates buttons in my gui when I load data. The number of buttons depend on the size of the XTickLabels and YTickLabels. If I load some other data I want that the buttons from the first data disappear and are replaced by the new amount of buttons. Don't now how I can remove the buttons and how the function knows if there are buttons or not. Here is the code of the button-creation:
s = size(x,2);
breiteQuadrat = 625/s
for n=1:s
handles.b{n}=uicontrol('Style','PushButton','Units','pixels', 'Position',[125-breiteQuadrat/2-5+breiteQuadrat*n 40 10 10],'Visible','on','Callback',@(obj,event)msgbox(num2str(n),num2str(n)));
end
t = size(y,2);
hoeheQuadrat = 625/t
for n=1:t
handles.c{n}=uicontrol('Style','PushButton','Units','pixels', 'Position',[40 125-hoeheQuadrat/2-5+hoeheQuadrat*n 10 10],'Visible','on','Callback',@(obj,event)msgbox(num2str(n),num2str(n)));
end

采纳的回答

Paulo Silva
Paulo Silva 2011-7-29
To detect if the buttons are in the figure
all(cellfun(@ishandle,handles.b))
To remove all the buttons
delete(handles.b{:})
Also look at your previous question, if the answer is what you wanted (seems to be) please accept it.

更多回答(1 个)

Teresa
Teresa 2011-7-29
Thanks for your answer. But another problem is, that the buttons will not be there when i start the gui. they are created when i load a matrix. if i try to delete the buttons first and then create new ones, it did not work at the beginning. I get the error: Reference to non-existent field 'b'.
Do you also have a solution for this problem? Can i ask if b is set? How?
  4 个评论
Teresa
Teresa 2011-8-1
sorry, forget the question above, this works. the function deletes the field of b when it exists but it did not remove the buttons from the figure. they are still there
Teresa
Teresa 2011-8-1
Now it works, i've updated the handles structure.
thank you for your help :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by