Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB Function my_fun that takes as its only input a vector of die valu

ID: 3686261 • Letter: W

Question

Write a MATLAB Function my_fun that takes as its only input a vector of die values vals (of length 5) and then sets its output variable to (returns) a number between 1 and 5 based on the following criteria: if all the values are the same if the values can be arranged to form a consecutive sequence if three of the values are the same, and the other two are also the same, but not the same as the first three: if exactly three values are the same, and the other two are unique 5: if not any of the above

Explanation / Answer

hey heres the code:

function x=func(A)
%checking for number 1
global fl=0;
for i= 2 : length(A)
    if A(1) == A(i)
        fl=1;
    else
        fl=0;
        break;
    end
end
if fl==1
    x=1
end
%checking for number 2
fl=0
for i= 2 : length(A)
    if A(1) == A(i)
        fl=1;
        break;
    else
        fl=0;
    end
end
if fl==0
    x=2
end
%now check for number 3

persistent count=0,s=0,t=0;
for i=1:length(A)
count=0
    for j=1:length(A)
        if A(i)==A(j)
            count+=1;
        end
    end
    if count>3
        f1=0;
        break;
    end
    if count==3
        s=1
    end
    if count==2
        t=1
    end
end
if s==1 & t==1
    x=3   %return 3
end

%check for number 4
count=0;
s=0;
for i=1:length(A)
count=0
    for j=1:length(A)
        if A(i)==A(j)
            count+=1;
           
        end
    end
    if count>3 | count==2
        s=0;
        break;
    end
    if count==3
        s=1;
    end
end
if s==1
    x=4 %return 4
end
x=5 %return 5 else
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote