MATLAB Answers

0

How to Call a function onto a separate script

Asked by Ivan Sandoval on 12 Oct 2019
Latest activity Answered by 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

Sign in to comment.

1 Answer

Answer by Image Analyst
on 12 Oct 2019
 Accepted Answer

Try something like this
TotalMinutes = 123; % Whatever
[Hours, Minutes, Message] = MyTimeConversion(TotalMinutes)
uiwait(helpdlg(Message));

  0 Comments

Sign in to comment.