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

main.m
function result = is1234(input)
    % Convert the input to a string to make it easier to search
    str_input = num2str(input(:)');
    
    % Check if '1', '2', '3', and '4' all exist in the input string
    result = contains(str_input, '1') && contains(str_input, '2') && contains(str_input, '3') && contains(str_input, '4');
end
332 chars
8 lines

related categories

gistlibby LogSnag