% "Gaussian" class: This example actually demonstrates how % to create plots with embellishments.Shown are steps to building a % program to plot a sine curve. % The "final" program follows the last set of "%" signs. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% First, the very basic stuff. %%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all % amp=5; period=2; phase=0.2*2*pi; omega=2*pi/period; % t=linspace(0,3*period); x=amp*cos(omega*t-phase); % plot(t,x) % fprintf(1,'%s\n','Press any key to continue...'); pause; close(gcf) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Next, add a second plot (no phase) %%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all % amp=5; period=2; phase=0.2*2*pi; omega=2*pi/period; % t=linspace(0,3*period); x=amp*cos(omega*t-phase); x0=amp*cos(omega*t); % plot(t,x,t,x0,'--') % fprintf(1,'%s\n','Press any key to continue...'); pause; close(gcf) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Now, add user input for parameters %%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all % amp=input('Amplitude: '); period=input('Period: '); phaseFrac=input('Phase as fraction of the period: '); phase=phaseFrac*2*pi; omega=2*pi/period; % t=linspace(0,3*period); x=amp*cos(omega*t-phase); x0=amp*cos(omega*t); % plot(t,x,'-r',t,x0,'--k') % fprintf(1,'%s\n','Press any key to continue...'); pause; close(gcf) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Finally, add titles, formats, etc. %%%%%%%%%%% %%% DON'T FORGET TO INCLUDE COMMENTS ! %%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all % % Input required parameters amp=input('Amplitude: '); period=input('Period: '); phaseFrac=input('Phase as fraction of the period: '); % % Calculate phase and frequency from inputs phase=phaseFrac*2*pi; omega=2*pi/period; % % Determine the graphed quantities, including an un-phase shifted curve t=linspace(0,3*period); x=amp*cos(omega*t-phase); x0=amp*cos(omega*t); % % Prepare a figure space; keep the handle hf=figure('PaperUnits','inches','PaperSize',[8,4]); set(hf,'PaperPosition',[0 0 8 4]) % % Plot the curves. Keep the handles and embellish the figure. hp=plot(t,x,'-or',t,x0,'--k'); set(hp,'MarkerFaceColor','r') set(hp,'MarkerSize',5) set(hp,'LineWidth',3) % % Add title and labels ht=title(['A=',num2str(amp),' T=',num2str(period),' \phi/2\pi=',num2str(phaseFrac)]); set(ht,'FontSize',25) xlabel('Time','FontSize',20) ylabel('Sine Curve','FontSize',20) % % Print to pdf file and close the figure print -dpdf PlotCommandsOutput.pdf close(hf)