I need help with grade calculator! thank you!!

조회 수: 1 (최근 30일)
Miss B
Miss B 2020년 3월 19일
댓글: Adam Danz 2020년 3월 23일
Afternoon Matlab Users,
Hope you're all having the best of days!
This is part of my class homework - I'm trying to make a grade calculator.
where there's a 'Edit Text' user input where 'Number' grade is calculated when pressed the assigned 'Push button'
and another 'Edit Text' where I want display the 'Letter' grade in accordance to the number grade above also via 'Push Button'
Below is my coding:
% --- Executes on button press in enter11.
function enter11_Callback(hObject, eventdata, handles)
if (handles.out19 >70 && <=100)
disp('You achieved a 1st');
elseif (handles.out19 >60 && <=69)
disp('You achieved 2:1');
elseif(handles.out19 >50 && <=59)
disp('You achieved 2:2');
elseif(handles.out19 >40 && <=49)
disp('You achieved 3rd');
elseif(handles.out19 >0 && <=39)
display('You failed');
end
and below is the defined error:
Error while evaluating UIControl Callback.
Relating to this, I also want to display the 'Letter grade' on a Panel.
But i'm struggling!
Help would be appreicated.
  댓글 수: 1
Adam Danz
Adam Danz 2020년 3월 23일
Copied here in case the question is edited/deleted as in a previous thead by OP.
----------------------------------------------------------------------------------------------------------
Afternoon Matlab Users,
Hope you're all having the best of days!
This is part of my class homework - I'm trying to make a grade calculator.
where there's a 'Edit Text' user input where 'Number' grade is calculated when pressed the assigned 'Push button'
and another 'Edit Text' where I want display the 'Letter' grade in accordance to the number grade above also via 'Push Button'
Below is my coding:
% --- Executes on button press in enter11.
function enter11_Callback(hObject, eventdata, handles)
if (handles.out19 >70 && <=100)
disp('You achieved a 1st');
elseif (handles.out19 >60 && <=69)
disp('You achieved 2:1');
elseif(handles.out19 >50 && <=59)
disp('You achieved 2:2');
elseif(handles.out19 >40 && <=49)
disp('You achieved 3rd');
elseif(handles.out19 >0 && <=39)
display('You failed');
end
and below is the defined error:
Error while evaluating UIControl Callback.
Relating to this, I also want to display the 'Letter grade' on a Panel.
But i'm struggling!
Help would be appreicated.

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

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 3월 19일
bushra - it isn't clear what handles.out19 is or how it is set, one problem is with
if (handles.out19 >70 && <=100)
and all the other conditions. Note that the condition should be written as
if (handles.out19 >70 && handles.out19 <=100)
and this will be true for all other conditions as well. If handles.out19 is a text control, then you will need to convert that value from a string to a number.
  댓글 수: 4
Miss B
Miss B 2020년 3월 19일
편집: Miss B 2020년 3월 19일
Hi again,
im so sorry for being this annoying :(
The code worked thankfully, but the only problem is...as shown on the above image - i want it to show on the 'Predicted Grade' text control rather than the command window.
Would I put the following command set(handles.in20,'string','');
Thank you.
I hope i can help you the same way you offered to help me.
Geoff Hayes
Geoff Hayes 2020년 3월 19일
Yes, the display calls will write the output to the command window. I thought that maybe these calls were just for debug purposes. If there is a specifc text control that you want to write to, then you need to do something similar to
set(handles.XYZ, 'String', strMessage);
where XYZ is the handle of the text control that you want to write to, and strMessage is the message that you want to display.
function enter11_Callback(hObject, eventdata, handles)
out19AsNumber = str2double(get(handles.out19, 'String'));
strMessage = '';
if out19AsNumber >70 && out19AsNumber <=100
strMessage = 'You achieved a 1st';
elseif out19AsNumber >60 && out19AsNumber <=69
strMessage = 'You achieved 2:1';
elseif out19AsNumber >50 && out19AsNumber <=59
strMessage = 'You achieved 2:2';
elseif out19AsNumber >40 && out19AsNumber <=49
strMessage = 'You achieved 3rd';
elseif out19AsNumber >0 && out19AsNumber <=39
strMessage = 'You failed';
end
set(handles.XYZ, 'String', strMessage);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by