This is an old revision of the document!
====== Formatting labs with Matlab publish ====== You can use the Matlab ''publish'' function to generate a nicely-formatted PDF of your lab work from a Matlab script. Here's an illustration that repeats material from today's lecture on estimating log-linear relationships from plots, as if it were work I wanted to turn in for lab 3. Write a matlab script in file ''lab3.m''. Note that this script loads a couple data files; these files are provided below. <code matlab> %% John Gibson, Lab 3 Math 445 %% Problem 1: % Fit function to x,y data in file data1.asc d = load('data1.asc'); % load data from file data1.asc into matrix d x = d(:,1); % assign 1st column of d to vector x y = d(:,2); % assign 2nd column of d to vector y fig = figure(1); fig.Position = [0 0 450 300]; % fig size 450x300 pixels clf(); % clear figure semilogy(x,y, 'bo-', 'linewidth', 1.5); % plot data as blue line hold on; % hold figure grid on % plot a coordinate grid yapprox = 400*10.^(-1.1*x); % constants estimated from graph of data plot(x, yapprox, 'r-', 'linewidth',1.5) % solid red line xlabel('x') ylabel('y') legend('data', 'approximation') title('Problem 1: exponential fit, y(x) = c 10^{mx}'); %% Problem 2: % Fit function to x,y data in file data3.asc d = load('data3.asc'); % load data from file data1.asc into matrix d x = d(:,1); % assign 1st column of d to vector x y = d(:,2); % assign 2nd column of d to vector y clf(); % clear figure loglog(x,y, 'bo-', 'linewidth', 1.5); % plot data as blue line hold on; % hold figure grid on % plot grid yapprox = 0.2*x.^(-0.58); % consts estimated from graph of data plot(x, yapprox, 'r-', 'linewidth',1.5) % solid red line xlabel('x') ylabel('y') legend('data', 'approximation') title('Problem 2: power-law fit y(x) = c x^m'); </code> Run the script through the Matlab ''publish'' function at the command prompt <code matlab> >> publish('lab3.m', 'pdf'); </code> This produces a file ''lab3.pdf'' in a ''html'' subdirectory <code matlab> >> ls html lab3.pdf </code> You can submit your lab work by uploading this file to Canvas.