I have a number of scripts which plots graph and want plot on GUI Axes by push buttons. How can I write on the callback to plot on axes referring to variables in workplace or link each script to each push button?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Young Lee
am 24 Okt. 2018
Beantwortet: Erik Keever
am 24 Okt. 2018
Heres what I have tried hold( handles.plotaxes,'off') % to replace with different graph per each button axes(handles.Axes1) attempt 1 X = A(:,2) plot (X) attempt 2 script1
attempt 3 run script1
0 Kommentare
Akzeptierte Antwort
Erik Keever
am 24 Okt. 2018
Event-driven GUI programming is about as close as it gets to the perfect use case for classes and OOP. The class can hold the data you want to play with, the handles for the figures/button/axes, and callback methods which get access to the class data. A bare minimum skeleton might look like:
classdef GUIClass < handle
properties (SetAccess = public, GetAccess = public)
foo;
bar;
theFigure;
end
methods (Access = public)
function self = GUIClass()
self.foo = rand(32,1);
self.bar = sin(2*pi*(1:32)/32);
self.theFigure = figure();
end
function buttonOneCallback(self, src, data)
figure(self.theFigure);
plot(self.foo);
end
function buttonTwoCallback(self, src, data)
figure(self.theFigure);
plot(self.bar);
end
end
end
Then a setup script would instantiate GUIClass, create/load the GUI and buttons, assign callbacks to buttonFooCallback and friends, and return the handle to the GUIClass.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!