minutes to hour and minutes

3 ビュー (過去 30 日間)
Waqas Siddique
Waqas Siddique 2020 年 10 月 5 日
回答済み: Star Strider 2020 年 10 月 5 日
I have a function that converts minutes to hours and minutes. it takes the value of minutes(mins) only once. However I want to update the value of variable mins several times(eg 10) so the variable output(test) is also updated the same number of times. How can I do this with example values of variable mins (60, 120,180,240,300).
hr_min = @(mins) [fix(mins/60) rem(mins,60)]; % Minutes —> [Hrs Min]
mins = 180; % Test Data
test = hr_min(mins) % Test Output

回答 (2 件)

James Tursa
James Tursa 2020 年 10 月 5 日
Make mins a column vector, or use mins(:) in your function handle.

Star Strider
Star Strider 2020 年 10 月 5 日
Use the (:) subscript convention to forec the ‘mins’ argument to be a column vector:
hr_min = @(mins) [fix(mins(:)/60) rem(mins(:),60)]; % Minutes —> [Hrs Min]
then:
test = hr_min([60, 120,180,240,30])
produces:
test =
1 0
2 0
3 0
4 0
0 30
.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by