CodeCodeCode

ENGR132: HW06 - MxN_matrix

May 6th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.91 KB | None | 0 0
  1. function [matrix_out] = MxN_matrix(row,column)
  2.  
  3. % FUNCTION: Makes a matrix where each cell is equal to its row
  4. % multiplied by its column
  5. %
  6. % INPUTS:
  7. % 1) row: The amount of rows the matrix will have.
  8. % 2) column: The amount of columns the matrix will have.
  9. %  
  10. % OUTPUTS:
  11. % 1) matrix_out: The final calculated matrix.
  12.  
  13. %Checks if row or column is negative or 0.
  14. if row <= 0 || column <= 0
  15.     new_matrix = 0;
  16. %If row and column are non-zero and positive.
  17. else
  18.     %For loop counts from 1 to the user's amount of columns.
  19.     for count_column = 1:1:column
  20.         %For loop counts from 1 to the user's amount of rows.
  21.         for count_row = 1:1:row
  22.             %Updates the matrix with the row * column calculation for every
  23.             %row and column.
  24.             matrix_out(count_row,count_column) = (count_row * count_column);
  25.         end %For (row) end
  26.     end %For (column) end
  27. end %If (checking) end
Advertisement
Add Comment
Please, Sign In to add comment