Storing of Array in Simulink

조회 수: 10 (최근 30일)
Abhijeet Kate
Abhijeet Kate 2024년 3월 4일
댓글: Abhijeet Kate 2024년 3월 11일
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
Sibghat
Sibghat 2024년 3월 4일
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 2024년 3월 4일
@Sibghat Multi-Dimensional Lookup Table block means " n D Lookup Table" ?

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2024년 3월 4일
편집: Fangjun Jiang 2024년 3월 4일
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
Abhijeet Kate
Abhijeet Kate 2024년 3월 11일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Representation in Generated Code에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by