===============IEEE MATLAB Seminar - m

advertisement
===============IEEE MATLAB Seminar - m-Files===============
1) m-Scripts
-How to create one
-Output
-To workspace (with semicolon)
-To command window (without semicolon)
-To plot (plot, stem, etc.)
-To file (save *.mat)
-Input
-Using existing workspace variables (call by name)
-Importing from a file (load *.mat)
-How to prompt for user input
-Outputing to the command window (display)
-Inputing from the command window (input)
-Basic Programming
-if (if, elseif, else, end)
-for (for n = 1:10, end)
-while (while(condition), end)
-switch (switch (test variable), {case}, {case}, ..., otherwise, end
-How to run it
-How to call from the command window (call example.m using example)
-"Run & Save" (F5)
-In-seminar exercise
-Write an m-script to plot e^x and label the graph
-Plot tan(x) and give the user an option to choose between the 2
2) m-Functions
-Basic definition of m-function
-How it differs from m-Script
-Inherent input, output
-Basic structure
-Passing variables
-Returning values
-Help file contents (first comment)
-How to call a function [call example.m using example(*, ..., *) where * is a
parameter]
-Function specific variables
-Allocating (x = 5)
-Deallocating (clear x)
-Controlling I/O
-clc (clear screen)
-clear (clear all variables)
-close all (close all plots)
-etc
-In-seminar exercise
-Write a function to square the given input if the input is less than 5 and
cube the input if the input is greater than 5
-Write a function that takes an array as its input and outputs the number of
negative numbers in the array (hint: use a for loop!)
Examples and Questions
===========================================================
EST. TIME: 40 minutes
Download