404 views
in Getting started by
İ need a matrix variable, arrays isnt working for me. Is there a way to create matrix with enum?

1 Answer

0 votes
by

Hello,

you can define an array to be multi-dimensional and in such manner access the array elements row/column-wise. If you want to store enum values in the array, use the enum-name as data type in the declaration of the array. See also:

To specify the size of the array member (also multi-dimensional) see: attribute Dimension.

To specify the data type of an array member see: attribute Type.

If the array is local (within a body of a method), see: statement array.

Hope it helps you further.

Best regards

Paul Banach

by
Thank you got i defined matrix.But my array is

float f2[46][5]={    2    ,8    ,16,    18,    22,
                    1,    3,    6.5,    7,    8,
                    13.9,    18.4    ,24.4    ,28.9,    31,  
                    35    ,115    ,180    ,200,    225,
                    20    ,20    ,20,    20,    20,
                    175    ,180,    180,    180    ,200,
                    175    ,180    ,180    ,180,    200,
                    12,    30    ,50    ,80,    100,
                
                    2,    5    ,8,    12,    22,
                    1    ,1.7,    2.5,    4,    8,
                    16.3,    19.5    ,22    ,24,    28.6,
                    28    ,56    ,81    ,111,    233,
                    50,    37    ,29    ,25    ,7,                        //job1 pulse var
                    100,    100,    100    ,100    ,100,
                    0.3,    0.3,    0.3,    0.3,    0.3,
                    340    ,340,    340    ,345,    345,
                    1.2    ,1.2    ,1.2,    1.2,    1.2,
                    0.4    ,0.4,    0.4,    0.4,    0.4,
                    15,    25    ,35    ,55    ,175,
                    3    ,3,    2.5,    2,    0.6,
                    0.4    ,0.4,    0.4,    0.4,    0.1,
                    15,    25    ,35,    55    ,175,
                    14    ,16,    20,    30,    80,
                    
                    1,    4,    8,    12    ,20,
                    1,    2,    4    ,6,    12,
                    10.9,    16.9,    19    ,28.9,    31.9,
                    27    ,90,    150    ,180,    255,                
                    20    ,20,    20,    20,    20,
                    125,    125,    125,    150,    200,
                    125    ,125,    125,    150,    200,
                    10    ,25,    75,    100,    150,
                    
                    2    ,4,    8,    12,    20,
                    1    ,2    ,3    ,4,    10,
                    18.7    ,20.2    ,23.5    ,27,    33,
                    30    ,57    ,118    ,164,    260,
                    20    ,20,    10    ,10,    10,                    //job 2 pulse var
                    200    ,200    ,200,    300,    400,
                    0.6    ,0.6,    0.6,    0.6,    0.6,
                    400,    400,    400,    360,    340,
                    1.2,    1.2    ,1.2    ,1.4,    1.6,
                    0.6    ,0.6    ,0.6,    0.4,    0.4,
                    10,    18    ,45    ,60,    150,
                    3    ,3,    3,    2    ,0.1,
                    0.4    ,0.4,    0.4,    0.4,    0.4,
                    10,    18    ,45,    60,    150,
                    6    ,10,    10,    10,    10,

                };

like this but way more bigger. It has 38940 float variables. İ cant initiliaze array it says not possible to initiliaze array while decleration got it im not doing that. i need to initiliaze whole matris not one by one
by

Hi,

the arrays in Chora are not so powerful as the arrays in 'ANSI C'. The simple initialization of the entire array, as demonstrated in your example above, is not possible. Can you explain me, what is the aim of the array in your application? Knowing this, maybe I can give you the right hint, how to deal with the array.

Alternatively, you can define the 'ANSI C' array inside a native statement and add code to access the array entries. For example:


var float result = 0.0;
var int32 col    = ...;  // column to read the array entry
var int32 row    = ...;  // row to read the array entry

$if !$prototyper
  native ( result, row, col )
  {
    static float f2[46][5]={    2    ,8    ,16,    18,    22,
                                1,    3,    6.5,    7,    8,
                             13.9,    18.4    ,24.4    ,28.9,    31,  
                             35    ,115    ,180    ,200,    225,
                             20    ,20    ,20,    20,    20,
                             ....
                            };

    result = f2[row][col];
  }
$endif

// the value read from the array is available in the Chora variable 'result'.
trace result;

This approach will work well on the target system. During prototyping, the target specific native code is not executed. Thus during prototyping, the variable result remains 0.

Best regards

Paul

Embedded Wizard Website | Privacy Policy | Imprint

...