Why won't my function display any of the required text?

11 visualizaciones (últimos 30 días)
Thomas Brown
Thomas Brown el 12 de Mzo. de 2024
Comentada: Thomas Brown el 12 de Mzo. de 2024
The function / script runs completely fine except for the fact that it won't print any of the disp(....) text form inside the function. If I remove the function start and end block and rerun it as a normal script it runs the entire thing perfectly and outputs everything I need it to.
Any ideas what I have done wrong?
function FinalGrade
FinalGrade = FinalMark;
PartBAvg = (sum(Results{1:6,7})/6);
PartCAvg = (sum(Results{7:18,7})/12);
FinalMark = ((PartBAvg*0.33)+(PartCAvg*0.66))
if (FinalMark >= 0) && (FinalMark <= 100)
disp ('Check Complete, all Results are within reasonable parameters')
else
disp ('Error in calculation. Check Data source')
end
if (FinalMark >= 70)
disp ('First Class Degree')
elseif (60 <= FinalMark) && (FinalMark < 70)
disp ('Upper Second Class Degree')
elseif (50 <= FinalMark) && (FinalMark < 60)
disp ('Lower Second Class Degree')
elseif (40<= FinalMark) && (FinalMark < 50)
disp ('Third Class Degree')
else
disp ('Fail')
end

Respuesta aceptada

VBBV
VBBV el 12 de Mzo. de 2024
%FinalGrade = FinalMark;
  7 comentarios
VBBV
VBBV el 12 de Mzo. de 2024
Editada: VBBV el 12 de Mzo. de 2024
@Thomas Brown, thats because you are not passing any input to the function FinaGrade. See the below format of the function.
function FinalMark = FinalGrade(Results)
% <-----> input variable data
end
Also note i have used Results as numeric array whereas you have cell arrays since you import data using readtable. So change the ( ) to { } for Results inside the function
Thomas Brown
Thomas Brown el 12 de Mzo. de 2024
That has now worked. Thank you for all your help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by