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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by