guidataの使用について
Show older comments
txtboxで記載した数値をguidataで取得し,別の関数で使用したいのですが上手くできませんでした。
guidataの使用が誤っているのだと思うのですが、どのように修正したら良いのかがわかりませんでした。 下記に途中まで作成したプログラムを記載します。 txtboxで記載した数値でプロットするsin波形のゲインを調節しようとしています。
初歩的な部分かもしれませんが,guidataの使用方法についてご教示のほどよろしくお願いいたします。
function buttonPlot
% Create a figure window
f = figure('Name','checking cutout start time');
% Create a UI axses1
ax1 = axes('Parent',f,...
'Units','pixels',...
'Position',[50, 220, 400, 170]);
% Create a UI axses2
ax2 = axes('Parent',f,...
'Units','pixels',...
'Position',[50, 20, 400, 170]);
% Create a txtbox1
txtbox1 = uicontrol(f,'Style','edit',...
'String','5',...
'Position',[460, 220, 100, 20],...
'Callback', @edit1_callback);
function edit1_callback(hObject,eventdata,handles)
input = str2double(get(hObject,'String'));
if isnan(input)
errordlg('You must enter a numeric value','Invalid Input','modal')
uicontrol(hObject)
return
else
display(input);
%guidata(object_handle,input)
end
end
% Create a push button
btn = uicontrol(f,'Style','pushbutton','String','update',...
'Position',[460, 120, 100, 20],...
'Callback', @pushbutton_callback);
%Create the wave1
x = linspace(0,2*pi,100);
y = sin(x)*rand;
plot(ax1, x, y,'k');
%Create the function for the ButtonPushedFcn callback
function pushbutton_callback(src,event)
x = linspace(0,2*pi,100);
y = sin(x)*rand%*input;
plot(ax2, x, y,'k');
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!