recurDiag

# recurDiag - you MUST use recursion in order to get credit...

This preview shows page 1. Sign up to view the full content.

% 10/21/2009 11:13 PM % Function Name: recurDiag % Inputs: 1. double array % 2. string % Outputs: 1. row vector % % Function Description: % If the second input is 'main' the function should find the diagonal % starting at the top left of the array and going towards the bottom, and % out put the numbers as a row vector. If the second input is 'other' the % function should find the diagonal starting at the top right of the % array going towards the bottom left, and output them as a row vector. % If the second input is not 'main' or 'other' the function should output % the string 'Invalid Input'. % % NOTE: - you may NOT use the diag() function
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % - you MUST use recursion in order to get credit. % % These are examples of 'main' diagonals, and 'other' diagonals. % % 'main' diagonal 'other' diagonal % * 0 0 0 0 * % 0 * 0 0 * 0 % 0 0 * * 0 0 % function vec = recurDiag(arr, str) if strcmp(str, 'main') vec = getDiag(arr); elseif strcmp(str, 'other') arr = arr(:,end:-1:1); % rearranges it so the last column is the first and so on vec = getDiag(arr); else vec = 'Invalid Input'; end end e function vec = getDiag(arr) if isempty(arr) vec = ; else vec = [arr(1) getDiag(arr(2:end, 2:end))]; % removes the first row and column and calls itself end end...
View Full Document

## This note was uploaded on 10/27/2009 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Tech.

Ask a homework question - tutors are online