matlab editor to simulink communication
2 次查看(过去 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!