Code covered by the BSD License  

Highlights from
plt

image thumbnail
from plt by Paul Mennen
An alternative to plot and plotyy optimized for data exploration

trigplt
% trigplt.m ------------------------------------------------------------
%
% This example demonstrates the use of the slider pseudo object as
% well as showing how to use the TraceMK parameter to show the line
% characteristics in the TraceID box.
%
% Text objects are used to display help information at the top of the
% plot window. This help text dissappears when any parameter is changed
% but can be re-enabled by clicking on the help button.

%
% ----- Author: ----- Paul Mennen
% ----- Email:  ----- paul@mennen.org
%
function trigplt
  S.tr = plt(0,zeros(1,6),'FigName','trigplt: y = A sin(Bx + C) + D',...
          'Right',1:2,'AxisPos',[1 1 1 .83 1 .8 1.3 1],'Options','-X-Y',...
          'FigBKc',[0 .25 .3],'Xlim',[0 2*pi],'Ylim',{[-8 8] [-1.5 1.5]},...
          'TIDcback',@sliderCB,'DisTrace',[0 0 0 1 1 1],'Position',[10 45 780 530],...
          'TraceID',['sin';'cos';'tan';'csc';'sec';'cot'],...
          'TraceMK',.5,'LabelX','radians','Styles','---:::',...
          'Markers',{'none' 'none' 'o' 'none' 'none' 'none'},...
          'Linewidth',{1 3 1 1 1 1},'LabelY',{'tan / csc / sec / cot' 'sin / cos'});
  S.tx = text(0,0,'','fontsize',14,'color','yellow','units','norm','pos',[.35 1.04]);
  p = [.04 .955 .2];  dp = [.24 0 0];
  S.sl = [plt('slider',p+0*dp,[1   0  1],'--- A ---',@sliderCB,[4 .01]);
          plt('slider',p+1*dp,[1   0 20],'--- B ---',@sliderCB,[4  .2]);
          plt('slider',p+2*dp,[0  -4  4],'--- C ---',@sliderCB,[4  .1]);
          plt('slider',p+3*dp,[0 -.5 .5],'--- D ---',@sliderCB,[4 .01],['%3w';'%4w';'%3w'])];
  S.hlp = [text(1.55,7.5,'Use the sliders to change the A,B,C,D paramters');
           text(1.80,6.7,'- Note that sin/cos use the right axis scale');
           text(1.80,5.9,'- The remaining functions use the left axis')];
  set(S.hlp,'units','norm','color',[1 .7 .7]);
  uicontrol('string','help','pos',[10 170 40 20],'CallBack',{@helpBTN,S.hlp});
  set(gcf,'user',S);
  sliderCB;            % initialize the plot
  helpBTN(0,0,S.hlp);  % enable help text
% end function trigplt

function helpBTN(h,arg2,t)  % toggle help visibility
   v = get(t(1),'visible');
   if v(2)=='n' v='off'; else v='on'; end;
   set(t,'visible',v);
%end function helpBTN

function sliderCB()  % Update the plot based on current slider values
  S = get(gcf,'user');
  set(S.hlp,'vis','off');
  A = plt('slider',S.sl(1),'get');   B = plt('slider',S.sl(2),'get');
  C = plt('slider',S.sl(3),'get');   D = plt('slider',S.sl(4),'get');
  v = findobj(gcf,'fontw','bold'); % trace names of all enabled traces
  s = sprintf('%.2f %s(%.2fx + %.2f) + %.2f',A,get(v(end),'str'),B,C,D);
  set(S.tx,'string',strrep(s,'.00',''));
  xx = pi*[0:.02:2];  x = B*xx+C+1e-12;
  f = A*[sin(x); cos(x); tan(x); csc(x); sec(x); cot(x)] + D;
  f(find(abs(f)>10)) = NaN;
  set(S.tr,'x',xx,{'y'},{f(1,:); f(2,:); f(3,:); f(4,:); f(5,:); f(6,:)})
%end function sliderCB

Contact us at files@mathworks.com