Create a Matlab code that sorts an inputted array of positive numbers. I am rest
ID: 645996 • Letter: C
Question
Create a Matlab code that sorts an inputted array of positive numbers. I am restricted from using the Matlab "sort" function. We must only use for loops and while loops. Thanks in advance Create a Matlab code that sorts an inputted array of positive numbers. I am restricted from using the Matlab "sort" function. We must only use for loops and while loops. Thanks in advance Thanks in advanceExplanation / Answer
function insertsort(array) array = [2 1 3 2 1] for i = 2:length(array) value = array(i); j = i - 1; while (j >= 1) && (array(j) > value) array(j+1) = array(j); j = j-1; end array(j+1) = value; end %forLoop disp(array); end %insertionSort