Variable-size matrix in Simulink
조회 수: 26 (최근 30일)
이전 댓글 표시
Hello everybody !
I have a question about variable size matrix in Simulink. Indeed, I would like to generate a matrix in Simulink (sized [1xN] or [MxN]), with M and N the dimensions of the matrix calculated in Simulink using Workspace variables.
However, Simulink does not understand this type of signal to be generated during the simulation, and must automatically refer to Workspace variables.
One solution I used to overcome this problem was to create a [1000x1000]-sized matrix of zeros, and assign the values I wanted in this matrix. I would then simply resize this matrix to a matrix of dimension MxN.
However, I have the same problem as before, even when trying different matrix resizing algorithms, because I need either M or N dimensions at a specific point.
Do you have any suggestions on how to do this ? Is it possible to get around this problem in an elegant way, or is it impossible on Simulink ?
Thanks in advance for your suggestions and answers ! Have a nice day ! :)
댓글 수: 0
채택된 답변
Rishav
2023년 9월 13일
Hi Hugo,
To generate a variable sized matrix in Simulink, you can use a MATLAB function block. Inside the MATLAB function block, you can write MATLAB code to create and populate the matrix.
Here is an example for the same:
function outputMatrix = generateMatrix()
%Calculate M and N based on your requirements
M = calculateM();
N = calculateN();
%Initialise a all zero matrix with the M*N dimensions
y = zeros(M,N);
%Populate the matrix with desired values
for i = 1:M
for j = 1:N
y(i,j) = calculatedValue(i,j); %Desired value calculation
end
end
Here in this code, calculateM() and calculateN() functions are used to calculate the desired value of dimensions M and N respectively. The function calculatedValue(i,j) is used to calculate the desired matrix elements.
Based on this, you can create a variable sized array in Simulink.
Thank you,
Rishav Saha
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!