Can you please help me out with the error in following program

1 view (last 30 days)
x=input('Enter the marks');
switch (x)
case {x>=90 && x<=100}
disp('O');
case {x>=80 && x<=89}
disp('A+')
case {x>=70 && x<=79}
disp('A');
case {x>=60 && x<=69}
disp('B+');
case {x>=50 && x<=59}
disp('B');
case {x>=40 && x<=49}
disp('c');
case {x<40}
disp('F');
otherwise
disp('No grade')
end

Answers (1)

Abdul Rehman
Abdul Rehman on 27 Oct 2018
Aditi.. Error is very simple
Basically && Operator in matlab perform Logical Operation.
You simply have to replace the && with &.
if true
x=input('Enter the marks');
switch (x)
case {x>=90 & x<=100}
disp('O');
case {x>=80 & x<=89}
disp('A+')
case {x>=70 & x<=79}
disp('A');
case {x>=60 & x<=69}
disp('B+');
case {x>=50 & x<=59}
disp('B');
case {x>=40 & x<=49}
disp('c');
case {x<40}
disp('F');
otherwise
disp('No grade')
end
end
Hopefully it's work for you..Thanks

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!