MATLAB: Hey matlab community. How to do data sorting without using loop instruction and and without using sort instruction. Please help

sort

i'm having no clue..

Best Answer

recursion can be used to replace a loop. It is usually aa bit awkward to do so but it is possible .
Instead of
for kk=1:length(VV); result(kk) = ff(VV(kk)); end
you can use
function result = recurseme(VV)
if isempty(VV ); result = []; else; result = [ff(VV(1)), recurseme(VV(2:end))]; end
I do not recommend this approach in MATLAB (but it is good in a language named SCHEME ), but if you really are given an assignment that cannot use any looping then recursion is what you do instead .
Related Question