Storing of Array in Simulink
Show older comments
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 Comments
Aquatris
on 4 Mar 2024
Abhijeet Kate
on 4 Mar 2024
Edited: Abhijeet Kate
on 4 Mar 2024
Aquatris
on 4 Mar 2024
Yes, you should be able to use it for scalar/vector/matrix/N-D array.
Sibghat
on 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
on 4 Mar 2024
Accepted Answer
More Answers (0)
Categories
Find more on Signal Attributes and Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!