How do I feed data into a simulink model from a .m file?

21 views (last 30 days)
apchar on 29 Apr 2013
Commented: Gordon on 10 Jun 2022
I've built a class project in simulink that we were supposed to do in a matlab function (I love simulink.) My model reads data from & writes data to the workspace. It works great but the prof wants it in matlab function form: y=f(x). Not a script, a function. He'll balk at anything else. The sim command lets me pass simulation parameters to the model but I don't see any way to feed a 1 million point array into an input port. How do you feed data to a simulink model from inside a matlab function?
Walter Roberson
Walter Roberson on 10 Jul 2018
Morrison Tay: the original question was about Simulink. Are you trying to work with Simulink, or are you trying to do this with MATLAB?

Sign in to comment.

Accepted Answer

Sachin Ganjare
Sachin Ganjare on 29 Apr 2013
If I understand your question correctly;
Define array variable in m file with a specific name (Eg. arr_1mil). Load this file in workspace. Then, use constant block in your model with array name arr_1mil. Connect this block to the input port of matlab function block.
Hope that will solve your problem.
Gordon on 10 Jun 2022
What about the sampling time. I'm inputting a file into simulink that is sampled at a lower rate. And then it causes errors.

Sign in to comment.

More Answers (1)

Kaustubha Govind
Kaustubha Govind on 30 Apr 2013
You can either use a From Workspace block or Import Data to Root-Level Input Ports if the data needs to be "streamed" to the model (as opposed to using a Constant block where n samples are treated as a signal of length n).
Walter Roberson
Walter Roberson on 10 Jul 2018
Also you should probably be creating a new Question for this.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!