4 36 points Write a MATLAB Function myfun that Takes as inp

4. (36 points) Write a MATLAB Function my.fun that: . Takes as input a String str as its only input. Determines if the value supplied in str is valid, based on the following ru (a) Its length is exact! (b) The frst and third characters are lowercase alphabetic characters. (c) The second and forth ch Sets the functions output variable to (returns) the result of your determi rules: aracters are dijsits ie. (0, 1, 2, 3, 4,5, 6,7,8.9 of your determination

Solution

% matlab code check if input string is valid or invalid

function returns = my_fun(str)
    if length(str) != 4
        returns = \"Invalid\"
    elseif isstrprop(str(1), \'lower\') == 0 | isstrprop(str(3), \'lower\') == 0
        returns = \"Invalid\"
    elseif isstrprop(str(2), \'digit\') == 0 | isstrprop(str(4), \'digit\') == 0
        returns = \"Invalid\"
    else
        returns = \"Valid\"
    end
end

result = my_fun(\"a9u9\");
disp(result);
% output: Valid

result = my_fun(\"A9u9\");
disp(result);
% output: Invalid

result = my_fun(\"A9u91\");
disp(result);
% output: Invalid

 4. (36 points) Write a MATLAB Function my.fun that: . Takes as input a String str as its only input. Determines if the value supplied in str is valid, based on

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site