Can someone help me with this function assignment

1 view (last 30 days)
I can't run this function (also autograde can't detect it and bypass, I got 0)
Do I need to change to name of the file to match with the MyTimeConversion?
There are also few other function in the same file though.
function [Hours,Minutes,Message] = MyTimeConversion (TotalMinutes)
MessageA='%d minutes are equal to %d hours and %d minutes.';
MessageB='%d minutes are equal to %d hours and %d minute.';
MessageC='%d minutes are equal to %d hour and %d minutes.';
MessageD='%d minutes are euqal to %d hour and %d minute.';
MessageE='%d minute is equal to %d hours and %d minutes.';
if Hours > 1 && Minutes >1
Message=sprintf(MessageA, TotalMinutes, Hours, Minutes)
elseif Hours > 1 && Minutes==1
Message=sprintf(MessageB, TotalMinutes, Hours, Minutes)
elseif Hours==1 && Minutes>1
Message=sprintf(MessageC, TotalMinutes, Hours, Minutes)
elseif Hours==1 && Minutes==1
Message=sprintf(MessageD, TotalMinutes, Hours, Minutes)
elseif Hours==0 && Minutes==1
Message=sprintf(MessageE, TotalMinutes, Hours, Minutes)

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 17 Jun 2021
Edited: John D'Errico on 17 Jun 2021
The name of the m-file must be MyTimeConversion.m, or MATLAB will not see it as such. You cannot have other functions in the same file either, if you want to be able to call them from MATLAB too.
John D'Errico
John D'Errico on 17 Jun 2021
Is the code correct? I don't really know, since I don't know exactly what you need to do. If you choose to ask, IMHO, the code seems a bit kludgy (ok, a massive kludge.) But if it works, that is irrelevant. The fact is, your question indicates that MATLAB cannot see the function, and that is why it is failing immediately. I explained why.
You should test your function in MATLAB, verifying that it returns that which is needed, and does so correctly.

Sign in to comment.


Find more on Loops and Conditional Statements in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by