Manipulating graph interactively

13 views (last 30 days)
Nishant Gupta
Nishant Gupta on 21 Jun 2011
Answered: Suraj on 4 Jan 2018
Those who are well versed with Mathematica might know of a command called 'Manipulate', which allow us to manipulate some variables through a bar and allow us to see the changes happening in the graph correspondingly...
Is there a similar kind of command/function in MATLAB, which can give us the same result as the above? Or a method to achieve the same effect...

Answers (3)

Matt Fig
Matt Fig on 21 Jun 2011
I am not familiar with this function, but you could put a slider in the same figure with the axes and have the callback for the slider adjust plotted parameters. Here is an example of what I mean:
function [] = slider_plot()
% Help goes here.
Sz = get(0,'screensize');
S.fh = figure('units','pixels',...
'position',[10 30 Sz(3)-10 Sz(4)-60],...
'menubar','none',...
'name','slider_ex',...
'numbertitle','off',...
'resize','off');
S.sl = uicontrol('style','slide',...
'unit','pix',...
'position',[80 20 Sz(3)-150 40],...
'min',1,'max',10,'val',1);
S.ax = axes('units','pix','pos',[80 100 Sz(3)-150 Sz(4)-240]);
% Now make some data. Your data may be different, but the approach is the
% same...
S.x = 0:.01:1;
plot(S.x,S.x);
legend('x^1');
set(S.sl,'call',{@sl_call}); % Set the Callback.
guidata(S.fh,S); % Save S for later...
function [] = sl_call(varargin)
% Callback for the slider.
S = guidata(gcbf); % Get the stored data.
V = get(S.sl,'val');
plot(S.x,(S.x).^V)
legend(['x^{',num2str(V,'%2.2f'),'}'])
guidata(gcbf,S) % Save the updated structure.

Fangjun Jiang
Fangjun Jiang on 21 Jun 2011
Not sure what you mean. From you title, you certainly can manipulate graph interactively.
h=plot(1:10,sin(1:10))
In the figure, click Tools>Edit plot. or in command window
plotedit(h)
propedit(h)

Suraj
Suraj on 4 Jan 2018
There is a GUI development Environment in Matlab, where you can create a GUI with sliders and graphs but the coding part may not be that straightforward but Matlab itself creates a template with half the code already typed as and when you modify the front end. It is not too complex and gets the job done. In Mathematica even though the coding is very compact and simple, there is not much freedom as to how your graph should be or where it should be placed. At those times, I switch back to Matlab. Try typing "guide" in your command prompt. Hope this helps.

Categories

Find more on App Building 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!