SimulinkをMATLABから操作するメモ

stop時間を指定する

詳細はSimulation stop time – MATLAB – MathWorks を見る。

set_param("hogemodel", "StopTime", '20')

ロギンングのon/off

詳細は信号のログ作成をオンまたはオフにする – MATLAB Simulink.sdi.markSignalForStreaming – MathWorksを見る。

x1_handles = get_param("hogemodel/hogeBlock","PortHandles");
x1         = x1_handles.Outport(1);
x2_handles = get_param("hogemodel/fugaBlock","PortHandles");
x2         = x2_handles.Outport(1);
Simulink.sdi.markSignalForStreaming(x1,"on");
Simulink.sdi.markSignalForStreaming(x2,"on");

ブロックが複数のOutportを持つ場合は Outport(2)などのようにindexを変更する。

Simulink.sdi.markSignalForStreaming(x1,”on”); などで、狙った箇所のロギングが有効になっているか確認すれば良い。

Simulinkのスコープから出力したFigureをいじる

下記はまとまっていない。本当に単なるメモ。

%%
fh_1 = gcf;

f_h_1.Position(3:4) = [800 800];

f_h_1.Children.Children(1).Children.Children(2).FontName = "Arial";
f_h_1.Children.Children(1).Children.Children(2).FontSize = 16;
f_h_1.Children.Children(1).Children.Children(2).Legend.Interpreter = 'none'
f_h_1.Children.Children(2).Children.Children(2).FontName = "Arial";
f_h_1.Children.Children(2).Children.Children(2).FontSize = 16;
f_h_1.Children.Children(3).Children.Children(2).FontName = "Arial";
f_h_1.Children.Children(3).Children.Children(2).FontSize = 16;
f_h_1.Children.Children(1).Children.Children(2).Legend.Interpreter = 'none'

%%
fh_2 = gcf;

f_h_2.Position(3:4) = [800 800];
ax = gca;
ax.FontName = "Arial";
ax.FontSize = 16;

あまり凝ったことしようとするなら、信号のログからplotで最初からグラフを作成するほうが楽だろう。

シミュレーションに時間がかかる場合などで信号をロギングしなおすのが時間を要するなど、scopeの結果をそのまま使いたい時なんかは上記のやりかたもある。

Adsense広告