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

Respuestas (1)

Steven Lord
Steven Lord el 3 de Sept. de 2020

0 votos

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.]

Categorías

Preguntada:

el 3 de Sept. de 2020

Respondida:

el 3 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by