How do I feed data into a simulink model from a .m file?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
apchar
am 29 Apr. 2013
Kommentiert: Gordon
am 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?
2 Kommentare
Morrison Tay
am 10 Jul. 2018
Bearbeitet: Walter Roberson
am 10 Jul. 2018
i have this data, how do i enter it into matlab using editor and command window to come out with my solution variable
Min Z= 1.80X1+2.0X2+0.52X3+3.6X4+12X5+0.1X6+16X7+0.32X8+26X9
Subject to
x1+ x2+ x3+ x4+ x5+ x6+ x7+ x8 + x9 ≤ 1000
8.8 x1+ 42x2+ 15.30x3+ 62x4+ 92x5+ 24.38x6+ 99x9 ≤ 21
4.0 x1+ 1.5x2+ 3.0x3+ 9x4 ≥ 0
2.1x1+ 7.0x2+ 8.3x3+ 0.50x4+ 12.45x6 ≥ 0
0.01x1+ 0.30x2+ 0.11x3+ 3.9x4+ 20x7+ 38x8 ≤ 0.89
0.25x1+ 0.65x2+ 0.65x3+ 2.54x4+ 0.23x6+ 0.02x8 ≤ 0.56
0.25x1+ 2.67x2+ 0.55x3+ 5.03x4+ 78x5+ 1.29x6 ≤ 1.28
0.16x1+ 0.58x2+ 0.2x3+ 1.92x4+ 0.35x6+ 99x9 ≤ 0.63
3350x1+ 2300x2+ 3300x3+ 3800x4+ 2550x6 ≤ 3107
x1+ x2+ x3+ x4+ x5+ x6+ x7+ x8+ x9 ≥ 0
Walter Roberson
am 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?
Akzeptierte Antwort
Sachin Ganjare
am 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.
2 Kommentare
Morrison Tay
am 10 Jul. 2018
pls can you give me a step by step answer because i am a new user of your program
Gordon
am 10 Jun. 2022
Hi,
What about the sampling time. I'm inputting a file into simulink that is sampled at a lower rate. And then it causes errors.
Weitere Antworten (1)
Kaustubha Govind
am 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).
5 Kommentare
Walter Roberson
am 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?
Siehe auch
Kategorien
Mehr zu Sources finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!