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

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

Accepted Answer

Tohru Kikawada
Tohru Kikawada on 18 Feb 2018
単純に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 Comment
test
test on 23 Feb 2018
とても親切な回答ありがとうございます! 大分イメージをつかむ事ができました。

Sign in to comment.

More Answers (0)

Categories

Find more on 対話型のモデル編集 in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!