Write a MATLAB function that will accept a cell array of str

Write a MATLAB function that will accept a cell array of strings and sort them into ascending order, according to the lexicographic order of the UTF-8 character set. (HINT: Look up function strcmp in the MATLAB Help System.)

Solution

function arr = sortArr(inArr)
    arr = {};
    for i = 1:length(inArr)
        min = inArr{i};
        for j = i:length(inArr)
            if string(min) > string(inArr{j})
                min = inArr{j};
            end
        end
        min
        arr(length(arr) + 1) = min;
    end
end

data = [\'Ronaldo\';\'Messi\';\'Bale\';\'Conor\'];
sortArr(cellstr(data))

Write a MATLAB function that will accept a cell array of strings and sort them into ascending order, according to the lexicographic order of the UTF-8 character

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site