How to Call a function onto a separate script

1 回表示 (過去 30 日間)
Ivan Sandoval
Ivan Sandoval 2019 年 10 月 12 日
回答済み: Image Analyst 2019 年 10 月 12 日
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

採用された回答

Image Analyst
Image Analyst 2019 年 10 月 12 日
Try something like this
TotalMinutes = 123; % Whatever
[Hours, Minutes, Message] = MyTimeConversion(TotalMinutes)
uiwait(helpdlg(Message));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by