I need help doing this short program

user is to input T1 in the formate hh:mm:ss
user is to input T2 in the formate hh:mm:ss
TM= 12:00:00
Tz= TM+T1-T2 (output in hh:mm:ss form)
Ty=(Tz/2)+T2 (output in hh:mm:ss form)
Tx=(Tz/3)*2 (output in hh:mm:ss form)
Tn=(Tx+T2) (output in hh:mm:ss form)

답변 (1개)

Chunru
Chunru 2022년 9월 1일

0 개 추천

Use duration function
% String
T1str = "02:30:31";
T2str = "08:06:45";
TMstr = "12:00:00";
% Convert to duration
T1 = duration(T1str)
T1 = duration
02:30:31
T2 = duration(T2str)
T2 = duration
08:06:45
TM = duration(TMstr)
TM = duration
12:00:00
% Duration calculation
Tz= TM + T1 - T2
Tz = duration
06:23:46
% Do the rest yourself

댓글 수: 5

Moe Joe
Moe Joe 2022년 9월 1일
Thanks, solution is OK, but I need program to prompt for the time of T1 & T2
Chunru
Chunru 2022년 9월 1일
You can use "input" function which is not possible in on-line platform here. doc "input" in matlab.
Moe Joe
Moe Joe 2022년 9월 1일
편집: Moe Joe 2022년 9월 1일
I try to use input fuction
but what is the correct way to input time in the formate: hh:mm:ss?
% T1str = "02:30:31";
% Change above into the following
T1str = input("Enter T1 in format hh:mm:ss", "s");
% Do the same for T2str
Moe Joe
Moe Joe 2022년 9월 2일
Perfect, thanks a lot dear Chunru...

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Octave에 대해 자세히 알아보기

질문:

2022년 8월 31일

댓글:

2022년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by