Borrar filtros
Borrar filtros

guidataの使用について

2 visualizaciones (últimos 30 días)
Ryosuke Takahashi
Ryosuke Takahashi el 24 de Oct. de 2018
Comentada: Ryosuke Takahashi el 29 de Oct. de 2018
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

Respuesta aceptada

Etsuo Maeda
Etsuo Maeda el 29 de Oct. de 2018
“うまくいかなかった”ときは、“どのようなエラーがでたのか”の情報があったほうが回答が得やすくなるかと思います。
guidata関数のドキュメンテーションをまずはよくご確認ください。
https://jp.mathworks.com/help/matlab/ref/guidata.html
GUIDEを使っている場合、データを格納するときは、
function MyPutFcn (hObject, eventdata, handles)
handles.MyData = 0;
guidata(hObject, handles)
end
データを読み出すときは、
function MyGetFcn (hObject, eventdata, handles)
data = guidata(hObject);
end
のようにして読み出します。
GUIDEを使っていない場合は、guihandles関数を使うのが便利です。
function MyPutGetFcn()
hObject = figure(1);
handles = guihandles(hObject);
MyPutFcn(hObject, handles)
MyGetFcn (hObject, handles)
function MyPutFcn (hObject, handles)
handles.MyData = 0;
guidata(hObject, handles)
end
function MyGetFcn (hObject, handles)
data = guidata(hObject);
disp(data.MyData)
end
end
  1 comentario
Ryosuke Takahashi
Ryosuke Takahashi el 29 de Oct. de 2018
ご教示頂きありがとうございました。
ドキュメンテーションもう一度確認し、不明な場合にはお聞きするかもしれませんがよろしくお願い致します。

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by