どうすれば、appd​esignerのバッ​クグラウンドでSim​ulinkを実行でき​ますか?

appdesignerで作成したアプリの画面上で、例えば"計算"ボタンを押すと、ボタンに対応したSimulinkモデルがバックグラウンドで実行され、計算結果がアプリの画面に表示される、というような事をしたいです。
サンプル「sf_fitness」がイメージに近いのですが、どのように実現されているかが分かりませんでした。 ご教授頂けると幸いです。
なお、使用しているバージョンはR2017bです。

 采纳的回答

単純にApp DesignerからSimulinkモデルの実行、停止、値の読み取りを行いたい場合には、 プログラムによるシミュレーションの実行 が参考になりそうです。
一方、時間や状態の管理をSimulinkで行いたい場合には sf_fitnessが近そうです。
モデルを開いてStateflowチャートの UI Controller を開いてみてください。
初期化ルーチンでApp Designerで作ったGUIを起動していることが分かります。
INIT
% Initialize Appdesigner app and import the App's interface.
en:
coder.extrinsic('sf_fitness_app', 'updateBeat', 'detectedActivity', 'updateSteps', 'updateClock', 'updateHeartRate', 'updateText');
app = sf_fitness_app();
さらに対応するApp DesignerのGUIを開くと、Simulinkモデルに値を反映している箇所を見つけられます。
>> edit sf_fitness_app
startupFcn を見てみると set_param でSimulinkのパラメータを変更してますね。
% Code that executes after component creation
function startupFcn(app)
% Get initial time from clock time
app.startTime = clock;
% Set initial states for the model
set_param('sf_fitness/Stop', 'Value', '0');
set_param('sf_fitness/Human_Simulator/Activity', 'Value', 'ActivityType.Rest');
set_param('sf_fitness/Human_Simulator/Strength', 'Value', '1');
app.Slider.Enable = 'off';
app.Button_Msg.BackgroundColor = [0.20, 0.80, 0.20]; %green
app.UIFigure.Name = 'SF_FITNESS';
app.Button_Msg.Icon = '';
app.Text_Step.Value = sprintf(' %d', 0);
pause(0.1);
app.UIFigure.Resize = 'off';
end

1 个评论

とても親切な回答ありがとうございます! 大分イメージをつかむ事ができました。

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Simulink 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!