Publishing MATLAB files for class

Updated February 2020

To my knowlege, Microsoft IE still does not view m-files properly. Use another browser like Chrome, Mozilla Firefox or Safari instead. Those browswers are safer to use in general.

This page is for mainly for my students for publishing their MATLAB assignments and projects. To do this, you must

  1. Format your .m file (for example, exampleFile.m) in a specific way (general information on formatting your MATLAB code for publishing, go to Publishing 2)
  2. Put it in a specific location on your G-drive to be viewable by me.

Here's a list of what you need to do (THESE ARE MY DIRECTIONS FOR MY CLASS!):

  1. It is best to work within the MATLAB Drive, so you can access these files from other computers and MATLAB Online. They are also less likely to be lost.
  2. Within the "www" directory/folder, create another directory/folder "loy#" (where # is your student ID number.) See below for how to create directories/folders within MATLAB
  3. Within that directory/folder, create another directory/folder that signifies the class. For example, create a directory named "ma302".
  4. Save your m-files (your script and any function files you need) in this directory/folder.
  5. Format your script file in such a way so that it "publishes" nicely (details below).
  6. There are several ways to publish the file once it is completed, some depending on how you are using MATLAB. Keep in mind that the default is to publish an "html" file.
    • Within the command window in MATLAB, on the command line type
      publish('exampleFile.m', 'pdf')
      
      MAKE SURE YOU HAVE THE CORRECT "CURRENT FOLDER" and FILENAME!
    • Within installed version of MATLAB: under the "Publish" tab, click on the arrow under the "Publish" button on the toolbar and choose "Edit Publishing Options..." Choose "pdf" for Output fiel format (first line under "Output Settings")
    • Within MATLAB Online: under the "Publish" tab, choose "Publish as PDF"
  7. In order to get full credit, your files must be named correctly, you must the appropriate text, commands, plots, etc. to answer the problems. Every published file must have the date/time published at the bottom. For example,
    
    %% Date/time published
    DateTimePublished = datestr(now)
      

image of caution symbol IMPORTANT: you can copy the template file (by doing a "save as") directly to the appropriate directory/folder in your MATLAB Drive.

To format your script file, use the exampleFile.m file or another template file you may be given specific to that assignment or project. The example file named exampleFile.m can be found at:
http://evergreen.loyola.edu/loberbroeckling/www/loy20181234/ma302/exampleFile.m

The published page can be seen at:
http://evergreen.loyola.edu/loberbroeckling/www/loy20181234/ma302/html/exampleFile.html

Remember, these files are SCRIPT files with the comments formatted a special way. I am not going into details of the formatting (go to Publishing 2 page for more details and examples of this). Here are 2 examples of the same script but one is "publishable" and the other is an ordinary SCRIPT file:
Basic2DPlotExample.m
Basic2DPlotExample2Web.m (publishable version)
webpage

Creating directories/folders within MATLAB

You can create the directories/folders within MATLAB if you're unsure of how to do it otherwise. To create a folder, in the "Current Folder" window (left of the command window if using the default view), click on the down-arrow to the right of the bluish circular icon and a pop-down list will appear in which you can select "New Folder" (click on images below to see screenshot).

Screen shot of MATLAB with the down-arrow in the right corner of the Current Folder window circled     Screen shot of MATLAB with the submenue containing New Folder selection circled