Multi Value Of a Dependent Variable

Hi, everyone.
I just want to ask about a variable that can be changed when it declared.
I have a variable called type with the function :
hour = [1:24];
min = [1:1440];
sec = [1:3600];
type = seconds(duration(hour(2), min(2), sec(2)) - duration(hour(1), min(1), sec(1)));
After that... I want to create a new variable based on the result of the variable of type. Let have the new variable as mr_x. I just want to make mr_x variable must to change the value based on these criteria :
If type variable = '1' , mr_x value is "seconds" (a scalar)
If type variable = '60' , mr_x value is "minutes" (a scalar)
If type variable = '3600' , mr_x value is "hours" (a scalar)
So basically, mr_x just has 3 kind of output : seconds, minutes, or hours once it declared....
Is that possible to create such a variable in matlab? Thank you everyone....

댓글 수: 4

switch type
case 1
mr_x = "seconds";
case 60
mr_x = "minutes";
case 3600
mr_x = "hours";
otherwise
% handle unauthorised values
end
Tyann Hardyn
Tyann Hardyn 2021년 8월 18일
편집: Tyann Hardyn 2021년 8월 18일
OMG, i forgot about that Switch thingy... Why did you answer my question in the comment column? I want to give you my gratitude as an " accepted answer ", Sir.....
Tyann Hardyn
Tyann Hardyn 2021년 8월 18일
Solved..
Thank you very much!!
Ive J
Ive J 2021년 8월 19일
My pleasure

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

답변 (0개)

카테고리

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

질문:

2021년 8월 18일

댓글:

2021년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by