My variables in workspace are updated but not on variables "From Workspace" to the simulink model
37 views (last 30 days)
Show older comments
Hi, dear Matlab users/experts.
I need create model, which able to received data (array of 20 elements) from up hardware interface, example, data is [1 2 3 4 5 6 7 8 9 ... 18 19 20].
This array is goes into a matlab function, which i perform data parsing to map my variables. Example:
byte1 value = 1 (1st element), it is mapped to Var01, and byte2 value = 2 (2nd element) is mapped to Var02 and subsequent variables is mapped in this order.
Following is my matlab function
function [] = my_func(u) global Var01; global Var02; : global Var20;
Var01 = u(1); Var02 = u(2); : Var20 = u(20);
When i run simulation, i can see that Var01, Var02, ... Var20 are updated respectively if the 20 elements of array are changed.
I am doing this is because my variables data order might changes time-to-time, so the array of data is goes to matlab function for data parsing.
Here comes the problem. In the model, i added Var01, 02 ... 20 as "From Workspace (source block)" and put display (or scope) at the point for these Var01, Var02 and etc ("From Workspace block). When running simulation, array is updated, so as variable in Workspace windows in Matlab, but WHY the "From Workspace" (display/scope) data is not updated???
Anyone know how to resolve this data "From Workspace" not updating issue???
Regards, William.
0 Comments
Answers (3)
Kaustubha Govind
on 31 Jan 2012
The best solution is to call your MATLAB function in a loop from your Simulink model using the Interpreted MATLAB Function block, so that the Var01, Var02, etc. can be continuously fed into the function, and their outputs routed back to the inputs of your model.
I think the reason that To Workspace blocks don't write the variable immediately it because it is very inefficient for To Workspace/File blocks to write the workspace/disk at every time-step, because these are slow processes than will slow down simulation. My guess is that they maintain a buffer that they write to at every time-step - the data is probably written to the final destination only when the buffer is full.
0 Comments
TAB
on 30 Jan 2012
Variable to be resolved in model using "From Workspace" block must be in time series Array or Structure formate. This means that, they should be defined at fixed time steps. The undefined values are interpolated using other values.
These values are loaded in the model when the simulation is started. So, when the values is changed in the workspace when simulation is running, model will not notice it.
0 Comments
See Also
Categories
Find more on Model, Block, and Port Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!