From: <Saved by Microsoft Internet Explorer 5>
Subject: 
Date: Thu, 14 Oct 2004 16:41:59 -0600
MIME-Version: 1.0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: 7bit
Content-Location: http://www.cs.usu.edu/~xqi/Teaching/CS5650F04/Notes/Example.m
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.2523" name=GENERATOR></HEAD>
<BODY><PRE>%%% 1. Basics
x = 4 ;
y = 8 ;
z1 = x + y, z2 = x * y ;

%%% Comments
%%% Use Control-C to stop the coding

%%% 2. Complex Numbers
c1 = 1 - j ;
real(c1)
imag(c1)
mag_c1 = abs(c1)
angle_c1 = angle(c1)
angle_c1 * 180 / pi

% help
% help elfun
% help specfun
% help images

%%% 3. number display formats:  
%% format short; 
%% format long; 

%%% 4. Useful comments in the script M-files
echo on
a = input('Please input a value: ') ;
b = a + 10
echo off

pause ;
display(a) ;

%%% 5. Array and Array Operations
%%%% Array Operation
x1 = [0 .1*pi .2*pi .3*pi 0.4*pi .5*pi .6*pi .7*pi .8*pi .9*pi pi] ;
y1 = sin(x1)
y1(5:end)
y1([5 9 10])
length(x1)

%%%% 6. Array Construction  -- Doing the same thing as 5
x2 = 0:0.1*pi:pi;
x3 = (0:0.1:1)*pi;
x4 = linspace(0, pi, 11) ;   %% first_value, last_value, number_of_values

a = 1:7 ;
b1 = a' 
b2 = (1:7)' 

a1 = a ;
a2 = [a1 1 3] ;
a = [a1 a2] ;

%%%% 7. Array Orientation
c1 = [1 ; 3 ; 5; 7] ;
c1'
c1.'
c2 =[1 + 2i ; 3+4i; 5+6i; 7] ;
c2'  %%% Please pay attention to the differences between .' and '
c2.'

%%%% 8. Scalar Array Mathematics
c1 - 2
2*c1 + 9

%%%% 9. Array-Array Mathematics
c1 - c2
c1 .* c2
c1 ./ c2

%%%%% 10. Standard Arrays
a = ones (3)
b = zeros(2, 5)
size(a)
ones(size(b))
eye(4)
eye(4, 3)
rand(4, 5)
c = randn(4, 5)
mean2(c)
mean(mean(c))
var(c(:))
std(c(:))


a = 1 : 2 : 8 ;
b = diag(a)
[r, c] = size(b)
r = size(b, 1)
c = size(b, 2)
n = numel(b)

d = pi ;
d * ones(4, 3) 
d + zeros(4, 3) 
repmat(d, 4, 3)

%%%% check out reshape function

A = [1 2 3 ; 4 5 6; 7 8 9] ;
B = A(3:-1:1, 1:3)
C = [A B(:, [1 3])] 
C(:, end) = []

%%%%% 11. Array Sorting
x = randperm(8) 
xs = sort(x) 
[xs, indx] = sort(x)

%%%%% 12. Array Searching
x = -3 : 3 
k = find(abs(x)&gt;1) 
x(k)

A = [ 1 2 3 4 ; 5 6 7 8] 
[i, j] = find(A &gt; 5)

%%%% 13. Array Manipulation Functions
A = [1 2 3; 4 5 6; 7  8 9]
flipud(A)
fliplr(A)
rot90(A)

%%%%% 14. Cell Array

D{1, 1} = [1 2 3 ; 4 5 6] ;
D{1, 2} = 5 ;
D(2, 1) = {'A string'} ;
D{2, 2} = 10:-1:1 ;


%%%% Control Flow
% for x = array
%     (commands)
% end

% while expression
%     (commands)
% end

% if expression
%     (commands)
% end

% if expression1
%     commands
% elseif expression2
%     commands
% else 
%     commands
% end

% switch expression
%     case test_expression1
%         commands
%     case test_expression2
%         commands
%     otherwise
%         commands
% end
</PRE></BODY></HTML>
