Advertisement
mess0011

project_4

Dec 4th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.04 KB | None | 0 0
  1. function [matrix, Min_matrix,Max_matrix,Sum,Tmatrix,multi_matrix] = project4(m,n,Min,Max)
  2. m = input('ammount of rows in the matrix: ');
  3. n = input('amount of columns in the matrix: ');
  4. Max = input('highest nr in your matrix: ');
  5. Min = input('lowest nr in your matrix: ');
  6.  
  7. % first Question: Create your Matrix
  8. matrix = randi( [Min Max], m , n )
  9.  
  10. % 2nd Question: The addition of all the matrixยดs numbers
  11. % Hand typed: sum(sum(ans))
  12. Sum = sum(sum(matrix))
  13.  
  14. %3rd Question: Transpose and multiply your matrix
  15. % Hand typed: transpose(ans)
  16. Tmatrix = transpose(matrix)
  17. multi_matrix = Tmatrix * matrix
  18.  
  19. %4th Question:  Find the Minimum and Maximum nr in matrix
  20. % Hand typed: max(max(ans)) and min(min(ans))
  21. Min_matrix = min(min(matrix))
  22. Max_matrix = max(max(matrix))
  23.  
  24. % %5th: rewrite all Min and Max numbers with Inf & -inf
  25. matrix(matrix == Max_matrix) = inf;
  26. matrix(matrix == Min_matrix) = -inf;
  27.  
  28. %6th Question: replace all odd numbers in your matrix with NAN
  29. % Hand typed: ans(rem(ans,2) == 1) = NaN;
  30. matrix(rem(matrix,2) == 1) = NaN;
  31.  
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement