User Tools

Site Tools


gibson:teaching:spring-2018:math445:lecture:publish

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

====== 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''. Mark the title and problems with ''%%''. Note that this script loads a couple data files; these 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. ====== Data files ==== <code text data3.asc> % x y 1.06e+00 2.22e+01 2.71e+00 3.38e-01 5.53e+00 2.72e-04 7.87e+00 7.39e-07 9.12e+00 3.19e-08 1.24e+01 8.06e-12 1.40e+01 1.41e-13 1.59e+01 1.05e-15 1.80e+01 5.32e-18 2.04e+01 1.13e-20 </code>

gibson/teaching/spring-2018/math445/lecture/publish.1517938663.txt.gz · Last modified: 2018/02/06 09:37 by gibson