Why the constant-block is much slower than from workspace-block when reading from matlab workspace
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Birdman
on 16 Jan 2018
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 Comments
Birdman
on 16 Jan 2018
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.
More Answers (0)
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!