Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- m = rand(6,4);
- disp('Initial matrix:');
- disp(m);
- for k=1:size(m,2)
- [m(:,k), s] = mysort(m(:,k), mod(k,2) == 1);
- disp(['Sum for column ' num2str(k) ' = ' num2str(s)]);
- end;
- disp('Sorted matrix:');
- disp(m);
- % То, что ниже, поместить в отдельный файл
- function [input, s] = mysort(input, order)
- n = length(input);
- s = 0;
- for j=1:1:n-1
- s = s + input(j);
- for i=1:1:n-1
- if order;
- if input(i)>input(i+1);
- temp = input(i);
- input(i) = input(i+1);
- input(i+1) = temp;
- end
- else
- if input(i)<input(i+1);
- temp = input(i+1);
- input(i+1) = input(i);
- input(i) = temp;
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment