Function help for structures
Afficher commentaires plus anciens
Hello, I am trying to find the individual final grade for each student then enter the values into the existing structure. How would I write this hard code %IndividualFinalAVG into a function ? Student 1 - 3 are from a structure i created. Also, how could i enter the avg's into a new field for each student into the existing structure ?
%Individual Final Avg
Total1 = numel(student(1).Grade)
y1 = sum(student(1).Grade)
indAVG1 = y1 / Total
Total2 = numel(student(2).Grade)
y2 = sum(student(2).Grade)
indAVG2 = y2 / Total2
Total3 = numel(student(3).Grade)
y3 = sum(student(3).Grade)
indAVG3 = y3 / Total3
Réponses (1)
Steven Lord
le 3 Sep 2020
0 votes
Don't use numbered variables. Use an array.
In fact if all your students have the same number of grades, I would store the data in a matrix rather than a struct array. That way I could just call mean and tell it to operate along the dimension representing each student. [See the description of the dim input argument on the documentation page for the mean function.]
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!