% 6.003: Signals and Systems - Spring '97
% S97Less1.M	Lesson 1 of MATLAB MiniCourse Demonstration script 
% 		by Pat Kreidl

%%%%% Generating Matrices
!clear
type 1.txt
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo on

A = [1 7; -4 8]		%2x2 matrix
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b = [9; 3]		%2x1 column vector
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c1 = [9 3]		%1x2 row vector
c2 = b'			%1x2 row vector -- via transpose
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
alpha = 1		%scalar
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
H = [A b]		%2x3 matrix -- via block form (DIMENSIONS!)
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
keyboard		%To continue, type:    return
t1 = [0:4]		%1x5 row vector -- via "colon"
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t2 = linspace(0,4,5)		%1x5 row vector -- via "linspace"
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t3 = [-1:0.2:0]'		%6x1 column vector -- via "colon"  
t4 = linspace(-1,0,6)'		%6x1 column vector -- via linspace
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t5 = [0:-0.2:-1]		%And again, in descending order
t6 = linspace(0,-1,6)  
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I1 = [1 0 0; 0 1 0 ; ...
       0 0 1]			%3x3 Identity Matrix
I2 = eye(3)			%3x3 Identity Matrix -- via "eye"
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Z1 = [0 0 0; 0 0 0]		%2x3 zero matrix
Z2 = zeros(2,3)			%2x3 zero matrix -- via "zeros" 
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
O1 = [1 1; 1 1; 1 1]		%3x2 ones matrix
O2 = ones(3,2)			%3x2 ones matrix -- via "ones"
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
txt = 'string'		%Can also generate matrices/vectors of characters
txt = ['s' 't' 'r'; 'i', 'n', 'g']	%Character-by-character example, 
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[numrows,numcols] = size(H)	%Getting dimensions of existing variables
numrows = size(H,1)		%Getting number of rows only
numcols = size(H,2)		%Getting number of columns only
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A			%Extracting elements from existing matrices
alpha = A(1,1)		%scalar, upper-left element of A
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
H		%can use the "colon" operator
A = H(1:2,1:2)          %2x2 matrix block, upper-left block of A
b = H(1:2,3)		%2x1 column vector, top of 3rd column of A
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = H(:,1:2)		%2x2 matrix block, all rows of left twp columns of H
b = H(:,3)		%2x2 matrix block, all rows of third column of H
F = H(:,[1 3])		%2x2 matrix block, 1st & 3rd columns of A
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
H		%can use the "size" function
A = H(1:size(H,1),1:2)		%2x2 matrix block, all rows of left twp columns of H
b = H(1:size(H,1),size(H,2))	%2x2 matrix block, all rows of third column of H
pause     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

echo off
clear
