Storing of Array in Simulink
Mostra commenti meno recenti
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
Aquatris
il 4 Mar 2024
Abhijeet Kate
il 4 Mar 2024
Modificato: Abhijeet Kate
il 4 Mar 2024
Aquatris
il 4 Mar 2024
Yes, you should be able to use it for scalar/vector/matrix/N-D array.
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
il 4 Mar 2024
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Signal Attributes and Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!