My variables in workspace are updated but not on variables "From Workspace" to the simulink model
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Kaustubha Govind
el 31 de En. de 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 comentarios
TAB
el 30 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!