Plotting to axes in GUI using seperate m-file
Show older comments
I am currently working on a project that requires me to control(send and receive data) a simulink model though a gui ex. Model.m that was created using GUIDE. I'm using an event listener callback within the simulink model to call a separate callback function ex. display.m Within this function i have been able to send and display numerical values within a static text box on my gui. The issue i am running into is accessing the axes plot within my gui from my display.m function, everytime i try to plot to my axes in the gui i get an error. Here is a snippet of the code from my display.m callback function.
In short all i want to do is plot to a selected axes on my gui(when its open) using another functuion in a seperate mfile.
function display( block,handles,hObject)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%---------Grabs data from stimulink file that is stored from the eventlistner functon--------
rpm = get_param('Simulation/Switch','RuntimeObject');
rpm1 = num2str(rpm.OutputPort(1).Data);
tq = get_param('Simulation/Switch1','RuntimeObject');
tq = num2str(tq.OutputPort(1).Data);
egt = get_param('Simulation/Switch2','RuntimeObject');
egt = num2str(egt.OutputPort(1).Data);
fuel = get_param('Simulation/Switch3','RuntimeObject');
fuel = num2str(fuel.OutputPort(1).Data);
%-----Displays value to needle using dialneedle fcn--------
axes(handles.axes1) % select the axes to plot on gui
dialneedle(rpm.OutputPort(1).Data)% creates plot
%----Displays values to command window-----
disp('------')
disp(['RPM = ' rpm1 ]);
disp(['Torque = ' tq ]);
disp(['EGT = ' egt ]);
disp(['Fuel = ' fuel ]);
%----pass outputs to gui text display-----
rpm1=num2str(rpm1);
tq=num2str(tq);
egt=num2str(egt);
fuel=num2str(fuel);
%get a handle to the GUI's 'current state' window
%revs= findobj('Tag','textRpmVal');
%trq= findobj('Tag','textTqVal');
%eg= findobj('Tag','textEgtVal');
%fue= findobj('Tag','textFuelVal');
Answers (1)
Geoff Hayes
on 26 Jul 2016
mitchell - how are you trying to access the GUI's axes? And, what error are you observing when you try to do so?
You can try "looking" for the GUI and then accessing it's handles structure if we make certain assumptions. Since you have used GUIDE to create the GUI, then in the Property Inspector for the GUI, set the HandleVisibility property to on, and the Tag property to MyGui (or some other unique identifier). Now, in your display function, you can do
function display(block) % not sure how block, handles, hObject are to be used
% get the handle of your GUI
h = findobj('Tag','MyGui');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to MyGui
handles = guidata(h);
if isfield(handles, 'axes1')
% draw something to handles.axes1
end
end
Try the above and see what happens!
Categories
Find more on View and Analyze Simulation Results 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!