Lecture 11 - Functions
Lecture 11 - Functions
Lecture 11 - Functions
Function
Functions
my_sum = a+b;
function y = mean(x)
% MEAN Average or mean value.
% For vectors, MEAN(x) returns the mean value.
Online Help
% For matrices, MEAN(x) is a row vector
% containing the mean value of each column.
[m,n] = size(x);
if m == 1
MATLAB
Code m = n;
end
y = sum(x)/m;
Select
Workspace
Set Auto-
Breakpoints
Set Breakpoint
Clear Breaks
Step In
Single Step
Continue
Quit Debugging
Example: Visual Debugging (2)
• Editor/Debugger opens the relevant file and identifies the
line where the error occurred.
Current
Current
Location
Workspace
(Function)
Example: Visual Debugging (3)
Error message
Access to
Function’s
Debug Workspace
Mode
Problem
function TinC=temp2(TinF)
TinF = input('Temperature in F: '); % get input
if nargin==0 % if there is no input
disp('no temparture was entered');
TinC=nan;
else
TinC = 5*(TinF - 32)/9; % conversion
disp(' ')
disp([' ==> Temperature in C = ',num2str(TinC)])
disp(' ')
end