wedMorningLec - B B-A A c Determining size of A size(A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
%% Input Example name = input('Enter your name: ','s'); age = input('Enter your age: '); fprintf('Your name is %s and you are %0.0f years old. \n', name, age) %% vectors x = 1:10; y = 0:0.5:5; z = sin(x) %% Code from Wed Morning Lecture x = [5 2 3] x = [5 2 3]; % suppress output x = [5,2,3] % commas or no commas - same y = [5,2,3;3 4 5] % 2x3 matrix A = [2 4 6; 2 4 6; 2 4 6] % 3x3 matrix B = [] % empty matrix whos % to see currect variables in workspace window B(1) = 3 % access first element in B B(2) = 3; % access second element in B B % print B to screen a = 1:5 % create vector with colon operator % linspace - equally spaces c = linspace(1,2,5) d = 1:0.25:5 % as opposed to this c = [2 3 4]; % overwritting c d = [3 4 5]; f = [5 6]; A = [c;c] % concatenation to create other matrices B = [f' f' f'] % transposing vectors and concatenation B = [f' f' d'] % will not work, wrong dimensions m = ones(3) m = ones(2) n = zeros(3) k = eye(3) % Math operations on matrices using scalar value k * 3 A A - 2 A + 3 A
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: B B-A A - c % Determining size of A size(A) % assigning size to a single variable s s = size(A) % accessing elements in size vector s(1) s(2) % assigning size values to separate variables [row col] = size(k) % using variables containing size values % is very useful for k = 1:row disp(k) end for k = 1:s(1) disp(k) end % determining LARGEST dimension of array length(d) length(n) % Using magic function magic(3) D = magic(3) % what is sum along columns sum(D) % what is sum along rows, transpose first F = D' sum(F) % Accessing elements with (row,column) d(1,3) % Accessing elements in array using single number % LINEAR INDEXING d(3) % Accessing elements with (row,column) D(3,2) % Accessing elements in array using single number % LINEAR INDEXING D(6) % Accessing parts of arrays t = D(3,1:3) g = D(3,1:end) h = D(3,:) r = D(3, 2:3) w = D(3, 2:end) q = D(end, 2:end) % Element by Element operations A.^2 A.*2 % Matrix Multiplication D*D size(D)...
View Full Document

This note was uploaded on 03/30/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Spring '08 term at Rutgers.

Page1 / 2

wedMorningLec - B B-A A c Determining size of A size(A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online