Create marks and names for 6 other subjects inside the same structure. Then write code that determines which subject has the highest mark. Once found, print the name of the subject with the highest mark to the command window.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sohail quadri
am 18 Mai 2020
Beantwortet: Devineni Aslesha
am 21 Mai 2020
So for this i have created a structure with 6 other subjects and marks my doubt is how should automatically print out highest marks form structure please help me.
This my struture below:
student.subjects(1).name='ENGG100';
student.subjects(1).mark=80;
student.subjects(2).name='ENGG102';
student.subjects(2).mark=70;
student.subjects(3).name='ENGG156';
student.subjects(3).mark=23;
student.subjects(4).name='ENGG678';
student.subjects(4).mark=58;
student.subjects(5).name='ENGG104';
student.subjects(5).mark=90;
student.subjects(6).name='MATHS142';
student.subjects(6).mark=78;
0 Kommentare
Akzeptierte Antwort
Devineni Aslesha
am 21 Mai 2020
Use the below code to find the subject with the highest mark and print the subject name.
len = length(student.subjects);
for i = 1:len
marks(i) = student.subjects(i).mark;
end
[M,Idx] = max(marks);
subName = student.subjects(Idx).name;
For more information, refer the following links.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!