Why the constant-block is much slower than from workspace-block when reading from matlab workspace
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone.
I have two following models (image attached with the models circled 1. and 2.) producing the same output with input from the matlab workspace. Model 1 uses input speed with dimensions of Nx1 (constant block). Model 2 uses input speed_time with dimensions of Nx2 (from workspace block), first column being the timetstamp.
Why is the first model so much slower to run than the second model? I prefer using the first model, since the input to the constant block can either be one single number, or a vector variable from the matlab workspace. Do you have any suggestions to make the first model more efficient? For example, how to transform the signal in efficient way, that I can input "speed" (variable from workspace) or "5" to the constant block and it produces the correct output without error? It works now, but it's very slow.
Thank you in advance!
0 个评论
采纳的回答
Birdman
2018-1-16
Well, if you want to know why the first model is slower than the second, just generate C code from two of them by building Build Model and see their difference. As a result, since first model contains more logic and so on, it will form more lines of C code and it will take more time to implement.
Furthermore, From Workspace block is the best option among its alternatives. If you want to give constant input from From Workspace block throughout the simulation, you can create a ones vector with the same length of first column, which contains time data. Something like as follows:
5*ones(numel(time),1)
4 个评论
Birdman
2018-1-16
Is there a way, with the callbacks, to detect the input from the mask to the From Workspace block and create variables accordingly
You may use get_param command for that purpose but note that those commands outputs variables in string format so you need to do a conversion. First set your variable on a mask before simulation and write the command with get_param to StartFcn. That might be a way to do it.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!