Storing of Array in Simulink

11 visualizzazioni (ultimi 30 giorni)
Abhijeet Kate
Abhijeet Kate il 4 Mar 2024
Commentato: Abhijeet Kate il 11 Mar 2024
Hello I need to store a 2 dimensional Array of like given below in Simulink. int matrix[10][4] = { {1, 4, 2,5}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1}, {-1, -1, -1,-1} };
So my data is comming from Radar through CAN massage , after doing parsing, I need to store the data in Array[10][4] in First row and other shoud be -1 and i also need to use the stored value in another part of module.
Can you tell me is there any why to store the value of array and create such array?
  5 Commenti
Sibghat
Sibghat il 4 Mar 2024
I think you can use a Multi-Dimensional Lookup Table block to store and access a 2-dimensional array.
Set the dimensions of the Lookup Table block to 10x4 to match your array size. and then initialize the values. Since you need to update only the first row with data from the radar and keep the rest as -1, you can use a MATLAB Function block or Simulink subsystem with Stateflow to update the values dynamically. In this block, you can write custom logic to update the first row of the array with data from the radar and set the remaining rows to -1.
The function can be something like this...
function y = updateArray(u)
persistent dataArray
if isempty(dataArray)
% Initialize the array with -1
dataArray = -1 * ones(10, 4);
end
% Update the first row with data from radar
dataArray(1, :) = u;
y = dataArray;
You can access the stored values from the output of the MATLAB Function block.
Abhijeet Kate
Abhijeet Kate il 4 Mar 2024
@Sibghat Multi-Dimensional Lookup Table block means " n D Lookup Table" ?

Accedi per commentare.

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 4 Mar 2024
Modificato: Fangjun Jiang il 4 Mar 2024
Unless necessary, you don't need a Data Store Memory block to "store" an array.
A Constant block can store the 10x4 array. Its output signal line carries (sotre) the 10x4 array value. If the first row is modified by the CAN receiver, you can use an Assignment block to update just the first row. The output signal line of the Assignment block will "store" the updated 10x4 array.
If the whole 10x4 array is from the CAN message, the output of the CAN receiver block carries (stores) the 10x4 array. You can pass the signal line anywhere it is used.
If there are multiple sources that will update the value, then it is proper to use the Data Store Memory block to store the array. Use multiple Data Store Write blocks to update the value. Use Data Store Read block to read the value.
MATLAB Function block is another way to store/update the array at its output. But the table data in the Lookup Table block is the parameter for the Lookup Table. Usually it can't be updated and used somewhere else in the model. "Lookup Table" block is the wrong block to be used for this task.
  3 Commenti

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by