How to Call a function onto a separate script
2 views (last 30 days)
Show older comments
Ivan Sandoval
on 12 Oct 2019
Answered: Image Analyst
on 12 Oct 2019
Hi, so I have a function in a script that I would like to call onto a separate script. Im not sure how write it out and was hoping that someone could help.
My function is:
function [Hours, Minutes, Message] = MyTimeConversion(TotalMinutes)
Hours1=TotalMinutes/60;
Hours=floor(Hours1);
Minutes= (Hours1-Hours)*60;
Message1= '%d minutes are equal to %d hours and %d minutes.';
Message2= '%d minutes are equal to %d hours and %d minute.';
Message3= '%d minutes are equal to %d hour and %d minutes.';
Message4= '%d minutes are equal to %d hour and %d minute.';
Message5= '%d minute is equal to %d hours and %d minutes.';
if Hours>1 && Minutes>1 %%1
Message= sprintf(Message1, TotalMinutes, Hours, Minutes)
elseif Hours>1 && Minutes==1 %%2
Message= sprintf(Message2, TotalMinutes, Hours, Minutes)
elseif Hours==1 && Minutes>1 %%3
Message= sprintf(Message3, TotalMinutes, Hours, Minutes)
elseif Hours==1 && Minutes==1 %%4
Message= sprintf(Message4, TotalMinutes, Hours, Minutes)
elseif Hours==0 && Minutes==1 %%5
Message= sprintf(Message5, TotalMinutes, Hours, Minutes)
end
end
Im trying to use this code in another script (call it) but not sure how as Mathworks is a little unclear
0 Comments
Accepted Answer
Image Analyst
on 12 Oct 2019
Try something like this
TotalMinutes = 123; % Whatever
[Hours, Minutes, Message] = MyTimeConversion(TotalMinutes)
uiwait(helpdlg(Message));
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!