hw12_problem4

hw12_problem4 - % Error: no function definition % Fix:...

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

View Full Document Right Arrow Icon
[new_matrix] = matrix_mod(A) % This function modifies the elements in an matrix based upon the following rules: % i. Square the value of each element if the number of rows in the matrix is equal to the number of columns. % ii. Divide the value of the each element by two if the number of rows is greater than the number of columns. % iii. Transpose the matrix if the number of columns is greater than the number of rows. (To transpose a matrix, you switch the rows and columns with each other.) % % INPUT ARGUMENTS: A = the original matrix % % OUTPUT ARGUMENTS: new_matrix = the modified matrix % % ---- Input Section ---- [n,m] = size(A); % determine the size of the input array New_matrix = zeros(n,m); % initialize new, modified matrix N % ---- Calculation Section ---- while n == m new_matrix = A^2; else while n > m new_matrix = A./2; else while n < m while c = 1:m while r = 1:n new_matrix(m,n) = A(r,c); end end end e % Line #: 1
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: % Error: no function definition % Fix: change to function [new_matrix= = matrix_mod(A). % % Line #: 13 % Error: New_matrix is initialized and never used % Fix: change to new_matrix. % % Line #: 16 % Error: uses while loop rather than conditional statement % Fix: change to if n==m. % % Line #: 18 % Error: uses else while rather than elseif % Fix: change to elseif n>m. % % Line #: 20 % Error: uses else while rather than elseif % Fix: change to elseif n<m. % % Line #: 20 % Error: uses else while rather than else % Fix: change to else. % % Line #: 21 % Error: uses while rather than for loop % Fix: change to for c = 1:m. % % Line #: 22 % Error: uses while rather than for loop % Fix: change to for r = 1:n. % % Line #: 23 % Error: new_matrix references a fixed location (m,n). % Fix: change to new_matrix(c,r). Note it should be c,r to return the % transpose of the matrix. %...
View Full Document

This note was uploaded on 05/02/2011 for the course ENGR 132 taught by Professor Kutson during the Spring '11 term at Purdue.

Page1 / 2

hw12_problem4 - % Error: no function definition % Fix:...

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