matlab editor to simulink communication
조회 수: 1 (최근 30일)
이전 댓글 표시
I have script that runs over 2000 iterations. Inside the loop i constantly update two variables say x and y whose size is 1 by N where is varying. the size of x is always equal to size of y. I need to export these x and y values to simulink for every iteration how do i do that?
my algorithm:
%some code
.
.
.
for i = 1:1:2000
%some code
....
N = randi(100);
x = rand(1,N);
y = rand(1,N);
%for every iteration I need to send the x and y vectors to simulink
end
Thanks in advance
댓글 수: 2
Walter Roberson
2023년 9월 11일
Are you running a complete model each time? Or are you stepping the model for (say) 0.1 seconds each time?
답변 (1개)
Walter Roberson
2023년 9월 11일
Write x and y into the base workspace, and use a From Workspace block in the model, which you would invoke using sim()
However, From Workspace is mostly for importing a signal -- something that has time information attached to it, with particular values to be released as signal inputs at particular times.
If what you have is instead arrays to be used in calculations, then instead of using From Workspace, use set_param() at the MATLAB level to set block properties. See https://www.mathworks.com/matlabcentral/answers/1653710-global-variable-in-simulink#comment_2009495 for some functions to construct real simulink signals (function RSS), real simulink parameters (function RSP) or complex simulink signals (function CSS)
댓글 수: 3
Walter Roberson
2023년 9월 11일
From Workspace of numeric values requires a 2D array, with the first column being treated as the time.
https://www.mathworks.com/help/simulink/ug/load-data-using-the-from-workspace-block.html describes the possibilities in more detail
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!