Question

use matlab to solve it
1. Write a function called MyTimeConversion with the following function declaration line. begin code function [Hours, Minutes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%The function MyTimeConversion that takes total minutes as input to the function
%Then find the total number of hours and total number of minutes for given total minutes
%The result of the function is stored in the Hours, Minutes and Message values

%Save this below code file as MyTimeConversion.m and run the file with the function name from Matlab as shown in %sample %output

-----------------------------------------------------------------------------------------------------------------

%MyTimeConversion.m
function[Hours, Minutes, Message] =MyTimeConversion(TotalMinutes)

%Divide TotalMinutes by 60 and get its floor value
%call floor method to get Hours
Hours=floor(TotalMinutes/60);
%call mod method to get Minutes as remainder value
%by dividing the TotalMinutes by 60
Minutes=mod(TotalMinutes,60);
  
%Concatenate the strings using strcat function
%num2str converts the number to string type
Message=strcat(num2str(TotalMinutes)," minutes are equal to ",num2str(Hours)," hours and ",
num2str(Minutes)," minutes");


end

-----------------------------------------------------------------------------

Sample Output:

>> [Hours, Minutes, Message] =MyTimeConversion(151)
Hours = 2
Minutes = 31
Message = 151 minutes are equal to 2 hours and 31 minutes


>> [Hours, Minutes, Message] =MyTimeConversion(120)
Hours = 2
Minutes = 0
Message = 120 minutes are equal to 2 hours and 0 minutes


>> [Hours, Minutes, Message] =MyTimeConversion(600)
Hours = 10
Minutes = 0
Message = 600 minutes are equal to 10 hours and 0 minutes

Add a comment
Know the answer?
Add Answer to:
use matlab to solve it 1. Write a function called MyTimeConversion with the following function declaration...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT