Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I group signal definitions per their data types in generated code?

1 回表示 (過去 30 日間)
mayuresh
mayuresh 2012 年 12 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am generting C code from a model which contains signals with different data types like integers, characters, words etc.
When generating code, I would like to group signal definitions all signals of same type together.
Foe example:
unit8 var1; uint8 var4;
uint16 var2; uint16 var3;
uint32 var5;
How can I achieve this?

回答 (1 件)

Jonathan
Jonathan 2012 年 12 月 18 日
The class() function can reveal what type of data is being input. To sort it you could check the class of the input and store it in a vector. This code is assuming your "input" is from an outside source so this is treated like a separate function call. If the input is internal then you could also use a for-loop around the switch-case
global array8 array16 array32
input = uint8(12);
switch class(input)
case 'uint8'
array8(end+1) = input;
case 'uint16'
array16(end+1) = input;
etc.
that's just a demo, you'd have to include
array8 = []
and stuff for that to be functional. If you're more specific we could help you out a bit better, but that should get you started :)
  1 件のコメント
mayuresh
mayuresh 2012 年 12 月 19 日
Thanks for the answer Jonathan. However, I would like these variables to be grouped directly in the generated C file.
So, if my model uses 3 UByte signals, 3 Uint signals , then when RTW generates C code I would like their declarations to be grouped together.

Community Treasure Hunt

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

Start Hunting!

Translated by