user1401864
user1401864

Reputation:

Setting a Simulink model Inport value from an m file

I've been doing a lot of research over the last few hours and I can't seem to figure out how to get and set a value to an Inport box. I have a simple model that has one inport and one outport and they are connected to each other. I want to set the inport value to 2 and run my simulation and see if my outport got set correctly. I read that you can't use set_param to set that value but you have to use sim(), but I'm not having any luck with that. So if anyone know how to look at the data in the inport box and/or how to set it, I'd appreciate it. Thanks!

Lucas

Upvotes: 0

Views: 7081

Answers (1)

Eugene
Eugene

Reputation: 11270

Ports in and out in Simulink don't work as you think. They are needed when you create subsystem - your own Simulink block, than you'll have your in and out ports.

But when you just want a make some model, and pass some data in it, and get results to Matlab, then you need To workspace and From workspace blocks. Some variable-name is assigned in their options, so you can set input data from your .m file and get results in matlab variables.

Block From workspace takes matrix variable, but if you want to pass just a number, you can use block Const and fill it value with a variable name.

Here is a screenshot, an example of in, out, to workspace and const blocks: enter image description here Here in example, I have input parameter x (block const), subsystem Gain5 and output parameter y (block To workspace). Inside the subsystem I use in and out blocks to get and return values.

Upvotes: 5

Related Questions