Running Previously User-Built MATLAB code from Simulink
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(4 个)
Fred Smith
2011-7-6
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 个评论
Fred Smith
2011-7-6
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 个评论
Andrew
2011-7-6
1 个评论
Alexander Bottema
2011-7-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!