Update plot on Axes in a Matlab GUI

조회 수: 7 (최근 30일)
chef13
chef13 2013년 8월 12일
댓글: ahasan ratul 2018년 4월 10일
Hi, I´m simulating a SIMULINK model and in this model I store some variables in the Worskspace.
I have a GUI and if AFTER the simulation I click on some buttons I have the plot of a certain variable.
An example of the plot of the 'Force' variable is this one:
% --- Executes on button press in plot_force_button.
function plot_force_button_Callback(hObject, eventdata, handles)
% hObject handle to plot_force_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
force = evalin('base', 'force');
axes(handles.axes7)
plot(force.time, force.signals.values,'r','LineWidth',2)
% xlabel('Time [s]')
ylabel('Force [N]')
grid on
title('Force Applied to the DE')
I would like to update the plot as the simulation runs.
I know it´s possible to do it with the Timer of MATLAB but I didn´t understand how :(.
Can you help me please?
Fab.

답변 (2개)

David Sanchez
David Sanchez 2013년 8월 12일
Take a look at the drawnow command. You will need it to draw your plot as the simulation goes.
doc drawnow

chef13
chef13 2013년 8월 12일
With drawnow it´s not working in real time!
I wrote in the run_button callback:
function run_button_Callback(hObject, eventdata, handles)
set_param('DEGREEN_Model_backup_3','SimulationCommand','start');
force = evalin('base', 'force');
axes(handles.axes7)
plot(force.time, force.signals.values,'r','LineWidth',2)
drawnow
% xlabel('Time [s]')
ylabel('Force [N]')
grid on
title('F_{ext} Applied to the DE')
But it is only drawing the last values stored in 'force' variable.
I´m quite sure that I have to use the timer objects but I have no clue how to do it!
  댓글 수: 1
ahasan ratul
ahasan ratul 2018년 4월 10일
could you find the solution? I am having a same problem with drawnow command in a gui axes. don't know how to solve it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by