connecting simulink with matlab

Hello
I want to know how to run a simulink model in the middle of my code in the matlab, so if I have a matlab code and in the middle of the code I want to write a command that runs the simulink model and then continue with the normal code.
assume the simulink model name is "mymodel"

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 1 月 27 日

0 投票

results=sim('mymodel')

8 件のコメント

ahmed abdelmgeed
ahmed abdelmgeed 2020 年 1 月 27 日
And I should upload the simulink model “mymodel” into matlab right ?
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 27 日
Yes. It could also be done by adding a line
open_system('mymodel')
ahmed abdelmgeed
ahmed abdelmgeed 2020 年 1 月 27 日
could you please tell me how to upload the simulink model in matlab. I tried using the import button but it doesn't work.
if I understood rights so at first I have to upload teh simulink model in matlab and then use the command
results=sim('mymodel').
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 27 日
There is no upload. in MATLAB, run
open_system('mymodel')
results=sim('mymodel')
Of couse, make sure your model file is in current directory or in the MATLAB path.
ahmed abdelmgeed
ahmed abdelmgeed 2020 年 1 月 27 日
thank you for your help it works but I had a problem with the code as you can see in the first picture the output should be a constant v = 10, while in the workspace it is saved as an arrar of 51 elements of 10's you can see that in the second picture in the workspaceScreen Shot 2020-01-27 at 7.38.29 PM.png
ahmed abdelmgeed
ahmed abdelmgeed 2020 年 1 月 27 日
second picture
Screen Shot 2020-01-27 at 7.38.45 PM.png
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 27 日
You need to learn some basics of Simulink. It's a simulation program. Those 51values correspond to the 51 time instances of the simulation. At time=0s, the value is 10. At time=0.2s, the value is 10, ..., etc.
ahmed abdelmgeed
ahmed abdelmgeed 2020 年 1 月 27 日
and how do I manage that ?

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

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2020 年 1 月 27 日

コメント済み:

2020 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by