Borrar filtros
Borrar filtros

Get workspace variables from Simulink into a GUI

5 visualizaciones (últimos 30 días)
Sindia Casado
Sindia Casado el 13 de Sept. de 2012
Hello all,
I am working with Simulink models and gui interfaces and I would appreciate help for the work I am doing. The main problem that I have is the following. Basically , i want to do the next. Firstable, I want to simulate my model in order to get some interesting output. Secondly, I want to plot this values in a gui. Then,I dont how to "get" this value in my gui in order to plot it. I presume that maybe i have to use the "get_param" command but i dont know what more I have to introduce in the programming. My idea could be the following. To begin with, simulate the model (I would put a "to workspace block" before). Then I get the values in the workspace , so how i can link that in a gui in order to plot it?
Thank you in advanced Sindia

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Sept. de 2012
Editada: Azzi Abdelmalek el 13 de Sept. de 2012
connect your output in your simulink model to "to file" blockc (in Simulink/Sinks').
in the "to file" block set the file name of the mat file where data will be saved suppose file1 is the name of output N°1. Set also the variable name (for example y )
after simulation (I guess you know how to lunch simulation by line command) you can read your data from file1.mat :
data=load('file1') % data is a struct variable
% the variable name is y then to get time and your signal output1
time=data.y(1,:);
output1=data.y(2,:)

Más respuestas (1)

Ryan G
Ryan G el 13 de Sept. de 2012
I'm working on an app (R2012b) that would show this functionality. Here is a snippet of code that shows you how to do it with the demo model vdp.
Type:
vdp
to open the model. In the GUI try something like this:
x1 = find_system(gcs,'findall','on','name','x1','type','line');
set_param(gcs,'SignalLoggingSaveFormat','Dataset')
set(x1(1),'DataLogging',1)
axes(handles.axes1);
cla;
sim('vdp');
x1plt = plot(data(1).Values.Time,data(1).Values.Data);
data = get(logsout,'x1');
set(x1(1),'DataLogging',0)
This was pulled from a GUI i already have so may not be 100% where it needs to be to work as is but you should get the point. If you use this on VDP it will enable logging, run the sim, plot the data, turn off logging. This is useful in a GUI if you do not wish to permanently alter the model for this functionality.
Azzi's logging file option is just as valid, and it is simply a matter of if yo u want to store the data versus just observing the plot.

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by