Write a function matsort to sort all of the values in a matrix (decide whether the sorted values are stored by row or by column). It will receive one matrix argument and return a sorted matrix
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:8| Question number:31.8
All Answers
total answers (1)
matsort.m
function outmat = matsort(mat)
% Sorts ALL of the values in a matrix and
% then stores them column-wise
% Format of call: matsort(matrix)
% Returns a matrix, sorted and stored by columns
[r c] = size(mat);
vec = reshape(mat, 1, r*c);
vs = sort(vec);
outmat = reshape(vs,r,c);
end
need an explanation for this answer? contact us directly to get an explanation for this answer