How to run model form m-file and save final values

2 ビュー (過去 30 日間)
Mike B
Mike B 2014 年 3 月 13 日
コメント済み: nl2605 2014 年 3 月 13 日
Hi all.
I already know how to run model form m-file using command
sim(model);
But how to save the final result. I have two Step and Sum block in model.mdl and in m-file
Step_time1 = 1;
Step_value1 = 2;
Step_time2 = 2;
Step_value2 = 3;
sim(step_sum);
Now, how to only import final Sum value at Tend (=5) in m-file, and save it in *.txt.
Thanks.

採用された回答

nl2605
nl2605 2014 年 3 月 13 日
The 'Outport' will help you get the values in MATLAB Workspace. From there you can use it in your m-file. If you also want to save it in .txt format, then use fopen,fprintf and fclose.
fileid = fopen('data.txt','w');
fprintf(fileid,Var1,Var2);
fclose(fileid);
where Var1 and Var2 are variable names you want to store in the text file.
  3 件のコメント
Mike B
Mike B 2014 年 3 月 13 日
In Workspace I get only tout, but no yout? In Simulation Date Export/Import both values are checked.
nl2605
nl2605 2014 年 3 月 13 日
You have to pass the signal to the OutPort. Then you will get yout too. I am posting a picture. Check that.
So now in this case at yout you have two columns, 1st column gives you the value of step signal and second column gives you the value of the addition of sine and step signals.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by