1. Basic plotting
  2. x=11
    y=-3
    z= 3x + y.^2
    doc plot
    plot (z,x, 'o') %all points are represented by symbol o. type help plot to see all the other formatting that you can use
  3. Use ezplot() to plot sinh(x). i.e 
  4. ezplot ('sinh (x)')
    ezplot ('(e.^x)- (e.^(-x))')
  5. The script below will allow you to use various commands to fit a certain type of data.
    • subplot to plot two graphs next to each other
    • fplot fo curve fitting
    • labelling and plotting graphs using xlabel, ylabel, gtext, grid, axis, legend
    • retrieve data from a graph using ginput
    • plot polar coordinates and fit polar coordinates using ezpolar
    • finally use inline to make scripts faster
    %==========================================================================
    % Clear up workspace! -----------------------------------------------------
    clear;
    %==========================================================================
    x= [1:1:100]; %data
    y = x.^4;
    plot(x,y);
    hold %holds the current plot
    z= x.^5; plot(x,z) %overlays the plot of z on x
    close all %close all figure windows
    % creating horizontal and vertical subplots--------------------------------
    %horizontal subplot
    subplot(1,2,1), plot(y); % represents the number of plots and their position (x,y,position).i.e in this case shows two graph side-by side.
    subplot(1,2,2), plot(z);
    user_entry = input('Break Task A'); %Break point
    
    %vertical
    subplot(2,1,1), plot(y);
    subplot(2,1,2), plot(z);
    user_entry = input('Break Task A'); %Break point
    close all %close all figure windows
    % fplot-fitting set of data to form a smooth curve--------------------------------------------------------------------
    fplot('[x^4, x^6]',[0:10])
    user_entry = input('Break Task A');
    close all
    
    % using plot to show multiple lines.
    plot (x,y,'b-',x,z, 'r-');
    xlabel('x');
    ylabel('y');
    title('figure 1');
    legend('data1', 'data2', 2);
    grid on; %shows the grid
    gtext('A') %slick of the mouse on the graph will paste the word A on it
    user_entry = input('Break Task A');
    
    % getting data from the graph
    grid on
    [xin,yin]=ginput(10); % have to click mouse 10 times and it will store x and y values in xin and yin respectively
    plot(xin,yin, 'rX') % plots xin and yin with a red X
    user_entry = input('Break Task A');
    
    %using polar coordinated------------------------------------------------------
    theta = [0: pi/10: pi/2];
    rho = cos(theta).^2;
    polar(theta, rho);
    user_entry = input('Break Task A'); %Break point
    
    %using fplot equivalent- ezpolar
    ezpolar('cos(t)^2', [0,pi/2]); %equivalent of fplot
    user_entry = input('Break point');
Advertisements