Clearing axes using created pushbutton in S-function

Hi,
I am calling a function clear in S-function which should clear the axes but It does not call the function when the button is pressed and nothing is cleared. Could anyone tell me what's wrong?
%Button:
uicontrol('Parent',m,...
'Style','pushbutton',...
'Units','normalized',...
'Position',[0.15 .15 0.7 0.2],...
'String','erase',...
'Callback',@clear);
%Clear Function:
Function clear()
cla;

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 1 月 27 日

1 投票

Why not just use @cla ? You not only overwrite the VERY IMPORTANT function clear, but you disguise what you're doing. Also when you declare the function, the keyword function is case sensitive.
h = figure;
peaks;
uicontrol('Parent',h,'Style','pushbutton', 'Units','normalized',...
'Position',[0.15 .15 0.7 0.2], 'String','erase', 'Callback',@cla);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 27 日

1 投票

When you specify a Callback function as a function handle or as a cell array, then MATLAB automatically adds passes in two arguments (often called "src" and "event" but the names do not matter). If the routine being called does not support being called with at least two arguments then MATLAB will error and will not execute the function.
Using Sean's cla idea:
[...]
'Callback', @(src,evt) cla )
Myself, I would also be specific about which axis to clear. See http://www.mathworks.com/matlabcentral/answers/22208-show-figure

1 件のコメント

koko kinder
koko kinder 2012 年 1 月 27 日
Thanks Walter, it works like a charm.

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

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by