How to protect an Embedded Matlab Function in Simulink?

조회 수: 3 (최근 30일)
Dani Tormo
Dani Tormo 2013년 6월 4일
Hi,
I have a subsystem which has a Matlab function. This subsystem has a parameter which specifies the size of an input vector signal.
It was working fine but I need to protect the code inside the m-function. I tried to instantiate the m-function to do it but now it comes this error:
Dimension 1 is fixed on the left-hand side but varies on the right ([1 x 6] ~= [:? x :?]).
I tried to use a reshape block inside the instantiated block and also in the main model without luck. I also specified the size of the input and output ports but nothing.
Anybody knows how to solve this or another way to protect the Matlab function code?
Thanks!
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2013년 6월 4일
By protected MATLAB code, I assume you mean a pcoded-file, correct? Is the error coming from the line where the .p file is called? Do you happen to know which line the error occurs at? If so, please paste the code at the line and what the variable(s) used on the right-hand-side of that line contains.

댓글을 달려면 로그인하십시오.

채택된 답변

Dani Tormo
Dani Tormo 2013년 6월 4일
편집: Dani Tormo 2013년 6월 4일
Finally!
Kaustubha gave me a clue to get it working.
The thing how I did it is:
1- In Simulink copy the code from the embedded Matlab function in a .m file (i.e. Program.m) and add at the beggining of the code this line:
coder.allowpcode('plain');
2- Generate the pcode file with Matlab:
>> pcode('Program')
3- Back to Simulink, remove the code in the embedded Matlab function and add this line to call the protected pcode file:
[output variables] = Program (input variables);
And that's all. Thanks Kaustubha!
Cheers!

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by