How Can I create a function as a string

조회 수: 2 (최근 30일)
Talha Tetik
Talha Tetik 2021년 12월 16일
댓글: Talha Tetik 2021년 12월 16일
Hı guys
Write a program that enters students' grades and gives them in the command window the mark they deserve (from A to F) with some comments. (write it as a function and M-file script )
How Can I do that?
function grade=input('Write the grade:';'s');
if grade=='A'||'a'
disp('excellent')
elseif grade=='B'||'b'
disp('well done')
elseif grade=='C'||'c'
disp('Great')
elseif grade=='D'||'d'
disp('better try again')
elseif grade=='F'||'f'
disp('Invalid grade')
else
end
end
I wrote this function but I have to ask to user the grades like A-B-C etc.
So how can ı write the input in the m-file

답변 (1개)

Sean de Wolski
Sean de Wolski 2021년 12월 16일
편집: Sean de Wolski 2021년 12월 16일
function grade=mygrade(grade)
arguments
grade(1,1) string = input('Write the grade:';'s')
end
grade = lower(grade);
if grade == 'a'
disp('excellent')
elseif grade == 'b'
disp('well done')
elseif grade == 'c'
disp('Great')
elseif grade == 'd'
disp('better try again')
elseif grade == 'f'
disp('Invalid grade')
else
end
end
  댓글 수: 1
Talha Tetik
Talha Tetik 2021년 12월 16일
thanks a lot but how can ı call this function

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by