How to Call a function onto a separate script
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2019년 10월 12일
Try something like this
TotalMinutes = 123; % Whatever
[Hours, Minutes, Message] = MyTimeConversion(TotalMinutes)
uiwait(helpdlg(Message));
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!