Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.75 KB | None | 0 0
  1. function matrix_sort
  2.     clc, close all;
  3.    
  4.     %%
  5.     inpSize = 6;
  6.     inpMtx  = randi([-100 100],inpSize,inpSize);
  7.    
  8.     disp('input:');
  9.     disp(inpMtx);
  10.  
  11.     outMtx  = magicStuff(inpMtx);
  12.    
  13.     disp('sorted:');
  14.     disp(outMtx);
  15. end
  16.  
  17.  
  18. function out = magicStuff(inp)
  19.  
  20.     [~,n]   = size(inp);
  21.  
  22.     for i = 1:length(inp(:,1))
  23.         for j = 1:length(inp(:,1)) - i
  24.             if inp(j,1) > inp(j+1,1)
  25.                 x           = inp(j,1);
  26.                 y           = inp(j,2:n);
  27.                
  28.                 inp(j,1)    = inp(j+1,1);
  29.                 inp(j,2:n)  = inp(j+1,2:n);
  30.                
  31.                 inp(j+1,1)  = x;
  32.                 inp(j+1,2:n)= y;
  33.             end
  34.         end
  35.     end
  36.    
  37.     out = inp;
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement