clc clear all clf disp('PURPOSE') disp(' How to plot data in MATLAB') % INPUTS % data points to be plotted xp=[0 1 2 3 4]; % x data points yp=[0 1 4 9 16]; % y data points disp('INPUTS') disp(' Data points to be plotted:') disp(' x y') disp(' ----------') disp([xp;yp]') % CODE % setting up the function to be plotted xf=[0:0.1:4]; % x domain as a vector yf=xf.^2; % y function to be plotted % plotting the first figure (data points and function) figure(1) hold on plot(xp,yp,'bo','MarkerSize',6) plot(xf,yf,'r-.','LineWidth',2) title('\bffunction and data points') xlabel('values of \itx') ylabel('values of \ity') legend('Data points','function, y=x^2',0) grid on hold off % plotting the second figure (only the function) figure(2) plot(xf,yf,'k-.','LineWidth',2) title('\bfy=x^{2}') xlabel('x points') ylabel('y points') grid off % COMMAND WINDOW OUTPUTS disp('OUTPUTS') disp(' See attached plots')