guideでワークス​ペースの変数を使用す​る方法について

3 次查看(过去 30 天)
Ryosuke Takahashi
Ryosuke Takahashi 2018-10-20
現在、ワークスペースで読み取ったデータをボタンプッシュで更新できるようにプログラムを作成したいです。 sin波で上図に元波形、下図に更新した波形が表示されるようにまではできたのですが、gideでワークスペースのデータを使用するにはどうしたらいいのかがわかりませんでした。
初歩的な質問かもしれませんが、ご教示いただけると幸いです。
よろしくお願いいたします。
function buttonPlot
% Create a UI figure window
fig = uifigure('Name','checking cutout start time');
% Create a EMG axses1
ax1 = uiaxes('Parent',fig,... 'Units','pixels',... 'Position',[50, 220, 400, 200]);
% Create a UI axses2
ax2 = uiaxes('Parent',fig,... 'Units','pixels',... 'Position',[50, 20, 400, 200]);
% Create a push button
btn = uibutton(fig,'push',... 'Text','update',... 'Position',[460, 120, 100, 20],... 'ButtonPushedFcn',@(btn,event) plotButtonPushed(btn,ax2));
% Create a wave
x = linspace(0,2*pi,100); y = sin(x)*rand; plot(ax1, x, y,'k'); end
%Create the function for the ButtonPushedFcn callback
function plotButtonPushed(btn,ax2) x = linspace(0,2*pi,100); y = sin(x)*rand; plot(ax2, x, y,'k');
end
  1 个评论
Stephan
Stephan 2018-10-20
编辑:Stephan 2018-10-20
Try of translation:
About how to use workspace variables in Guide
Currently I would like to create a program so that I can update data read by workspace with button push. Although it was possible to display the original waveform in the upper figure above and the updated waveform in the lower figure with the sin wave, I did not know how to use workspace data with gide.
Although it may be an elementary question, I would be pleased if you could teach.
Thank you.
function buttonPlot
% Create a UI figure window
fig = uifigure('Name','checking cutout start time');
% Create a EMG axses1
ax1 = uiaxes('Parent',fig,... 'Units','pixels',... 'Position',[50, 220, 400, 200]);
% Create a UI axses2
ax2 = uiaxes('Parent',fig,... 'Units','pixels',... 'Position',[50, 20, 400, 200]);
% Create a push button
btn = uibutton(fig,'push',... 'Text','update',... 'Position',[460, 120, 100, 20],... 'ButtonPushedFcn',@(btn,event)
plotButtonPushed(btn,ax2));
% Create a wave
x = linspace(0,2*pi,100);
y = sin(x)*rand;
plot(ax1, x, y,'k');
end
%Create the function for the ButtonPushedFcn callback
function plotButtonPushed(btn,ax2)
x = linspace(0,2*pi,100);
y = sin(x)*rand;
plot(ax2, x, y,'k');
end

请先登录,再进行评论。

采纳的回答

Naoya
Naoya 2018-10-23
ご質問の主旨としては コールバック関数 plotButtonPushed() から、ベースワークスペース変数 x,y を使用して、 ax2 上にプロット表示されたいということになりますでしょうか?
evalin() と呼ばれるコマンドで、指定したワークスペース上でMATLAB 式を実行することができますので、こちらを利用されてはいかがでしょうか?
function plotButtonPushed(btn,ax2)
%x = linspace(0,2*pi,100);
%y = sin(x)*rand;
x = evalin('base','x'); % ベースワークスペースの x を読み込む
y = evalin('base','y'); % ベースワークスペースの y を読み込む
plot(ax2, x, y,'k');
end

更多回答(1 个)

Ryosuke Takahashi
Ryosuke Takahashi 2018-10-23
私の説明不足で申し訳ありません。ご教示頂いた内容で問題ありませんでした。
おかげさまで無事に解決しました。
ご教示頂きありがとうございました。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by