Automatic generation of S function for a c code

I have a C code and want generate S function for it using matlab scripting..(Avoid manual steps required for s function generation)..Can any one help me for this

 採用された回答

Kaustubha Govind
Kaustubha Govind 2013 年 7 月 22 日

0 投票

You can use the Legacy Code Tool to generate a C-MEX S-function wrapper for your C-code.

6 件のコメント

Rupesh
Rupesh 2013 年 9 月 1 日
Thanks Kaustubha for the answer...It seems to be working for me...Additionaly I have one more question: My C function does not have any input argument nor it returns anything(it is of kind void main(void))...But I need to provide some input values for the internal signals of c code and simillarly I need to take few internal variables as output variables from the s function that will be created from my c code....Could you please let me know how it can be done...
Kaustubha Govind
Kaustubha Govind 2013 年 9 月 3 日
Rupesh: Not sure what you mean by "internal variables". How would you provide/access the values if you were writing the code outside of Simulink?
Rupesh
Rupesh 2013 年 9 月 6 日
suppose my code is like
main() { int a,b,c; c=a+b; }
As main function does not take any input argument nor it returns anything.. In my problem I have to pass values of variable a and b from matlab environment and then take out variable c in matlab environment
Walter Roberson
Walter Roberson 2013 年 9 月 6 日
How are the values stored in the MATLAB environment? Is there a reason you are not using a From Workspace block feeding parameters to the S function ? If changing the C code is not allowed, then how does the C code get its values at the moment?
Rupesh
Rupesh 2013 年 9 月 7 日
I have to connect these variables(here a and b) using inports in Simulink. and will provide values through test vectors in .m file.. On the same lines output c should be connected to outport of Simulink..
Looking after for your answer
Kaustubha Govind
Kaustubha Govind 2013 年 9 月 9 日
Rupesh: Walter's question was about how you might invoke the C code from another C application and supply inputs. It seems to me that you have to rewrite your C code so that the inputs a and b are passed in as function argument and c as a return argument. Once you have done that, you can use the Legacy Code Tool to generate an S-function so that the block inputs are passed in to 'a' and 'b' and 'c' is assigned back to the block output.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by