Running Previously User-Built MATLAB code from Simulink
1 view (last 30 days)
Show older comments
I have created a function wrapper (interval_sim_callv4())around MATPOWER's functions all coded through MATLAB. I also created a function (GrabSysElements())in MATLAB to find my user-defined masked block types, how many there are, and their parameters a user has built in simulink using find_system() and get_param().
I want to run these m-files I created in MATLAB after a user builds a system of blocks and sets their parameters. These parameters will be used to create another m-file with a data structure to give parameters in the format MATPOWER uses.
How can I get around the coder.extrinsic strategy so I can avoid changing literally over 100 files of code which also use local variables and such which Embedded MATLAB is not capable of working with? Many of these variables are dynamic and change based upon a user's new creation of a simulink model.
0 Comments
Answers (4)
Fred Smith
on 6 Jul 2011
Hi Andrew,
Could you please provide a bit more detail?
I am puzzled by how coder.extrinsic became involved in this? What is your goal? Are you changing the behavior of the Simulink model? Are you generating code from MATLAB? Is your goal acceleration or code generation? What kinds of functions are you using that you need to put coder.extrinsic everywhere? Why do you say that Embedded MATLAB cannot handle local variables? That isn't true. When you say that the variables change, when do they change?
As you can see I have lots of questions.
Thanks,
Fred
0 Comments
Fred Smith
on 6 Jul 2011
Hi Andrew,
Could you please provide a bit more detail?
I am puzzled by how coder.extrinsic became involved in this? What is your goal? Are you changing the behavior of the Simulink model? Are you generating code from MATLAB? Is your goal acceleration or code generation? What kinds of functions are you using that you need to put coder.extrinsic everywhere? Why do you say that Embedded MATLAB cannot handle local variables? That isn't true. When you say that the variables change, when do they change?
As you can see I have lots of questions.
Thanks,
Fred
0 Comments
Andrew
on 6 Jul 2011
1 Comment
Alexander Bottema
on 7 Jul 2011
You can use 'coder.varsize(...)' to declare a variable to be of variable size. For the MATLAB function block in Simulink (formerly known as the Embedded MATLAB function block) you have to specify the maximum size on how big this array can be. To get the length of an array you could extract the sizes for all dimensions (size(x)) or the total number of elements (numel(x)).
Another option to create variable size arrays is to put value constraints when calling a matrix constructor (zeros/ones/repmat).
For example,
% ...n is some input from a function...
assert(n <= 10);
x = zeros(1,n); % create a matrix 1xN where N is at most 10.
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!