Giter VIP home page Giter VIP logo

manipulate's Introduction

Manipulate

MATLAB interactive function caller

A very simple implementation after Mathematica's function Manipulate, this function creates a slider that calls a function whenever its value is updated. Great for interactive plotting.

manipulate(@(ARGS)FUNC(ARGS),{LABEL,ARG_MIN,ARG_MAX,[DEFAULT]}...) calls the function func(ARGS) and allows the user to control the values of the arguments via sliders. If DEFAULT is not set, the value is initially set to ARG_MIN.

manipulate expects one cell input per argument. All arguments must be scalars. Cells can also be of the form {LABEL,VALUES,[DEFAULT]} where VALUES is a 1D array containing allowed values of the argument.

H = manipulate(...) returns the the slider handles.

manipulate(...,'UpdateMode',MODE) allows the user to set the frequency with which the function is called. 'Low' Refresh only when slider is released (after drag) or clicked, or when edit field is altered. 'High' Also refresh continuously as slider is dragged. [Default] 'Manual' Refresh only when user presses button.

manipulate(...,'SliderStep',[SMALL BIG]) allows the user to set the step size of incremental slider increases and decreases. See UICONTROL for details.

Examples:

Sine Waves

  x = 1:.001:10;
  gca, L = plot(1,1,1,1);
  myfunc = @(i,f,theta)set(L(i),'XData',x,'YData',sin(10*x)+sin(f*x+theta));
  h=manipulate(@(f,theta)myfunc(1,f,theta),{'frequency1',10,20},{'phase1',0,2*pi});
  manipulate(h,@(f,theta)myfunc(2,f,theta),{'frequency2',10,20},{'phase2',0,2*pi})

Plots the interference of two sine waves and allows the user to manipulate the frequency and phase offset of the second wave. Then does the same again, adding the slider controls to the existing slider figure.

Gaussian Distribution

 x = linspace(-10,10,1e4);
 fig = figure('Visible','off');
 ax = [subplot(2,1,1),subplot(2,1,2)];
 f1 = @(u,s) plot(ax(1),x,exp(-1/2*((x-u)/s).^2)/sqrt(2*pi)/s,'r');
 f2 = @(u,s) title(ax(1),sprintf('N(%.2f,%.2f)',u,s^2));
 f3 = @(u,s) plot(ax(2),x,erf((x-u)/s/sqrt(2))/2+1/2,'r');
 myfunc = @(u,s) {f1(u,s),f2(u,s),f3(u,s)};
 manipulate(fig,myfunc,{'Mean',-5,5,0},{'Standard Deviation',.01,5,1})
 linkaxes(ax,'x'), set(ax,'NextPlot','replacechildren')
 movegui(fig,'onscreen')
 set(fig,'Visible','on')

Plots the normal distribution and its cumuliative distribution on separate subplots and allows the user to manipulate the mean and standard deviation. The mean is initially set to 0 and the standard deviation to 1. The slider controls appear in the same figure as the subplots.

Created by: Robert Perrotta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.