write a function is1234() that takes a numeric vector or matrix as an input and returns whether it contains the numbers 1,2,3,4 in any order in matlab using loops in matlab

main.m
function result = is1234(input)
    if isvector(input)
        % Check if the array contains 1, 2, 3, 4
        foundNumbers = zeros(1, 4);
        for i = 1:numel(input)
            num = input(i);
            if num == 1 || num == 2 || num == 3 || num == 4
                foundNumbers(num) = 1;
            end
        end
        % If all numbers are found
        if all(foundNumbers)
            result = true;
        else
            result = false;
        end
    else
        result = false; % Input is not a vector
    end
end
539 chars
21 lines

related categories

gistlibby LogSnag