フィルターのクリア

Divide a number by time

4 ビュー (過去 30 日間)
Michela Longhi
Michela Longhi 2016 年 12 月 1 日
編集済み: dpb 2016 年 12 月 1 日
Hi,
I have a time express in duration
t =
duration
00:01:12
and I want to divide a number n=9 by t: Y=n/t
But how can I do it? I should convert the time duration in a number as 1,12 and then divide?
Help me, please
  2 件のコメント
Brendan Hamm
Brendan Hamm 2016 年 12 月 1 日
What does n represent? What are you expecting the output to be?
Michela Longhi
Michela Longhi 2016 年 12 月 1 日
n is a number of lectures, and I expected to obtain a Y which should be the number of lectures normalized by time (t).

サインインしてコメントする。

採用された回答

dpb
dpb 2016 年 12 月 1 日
Convert the time to lowest common interval; looks like seconds and divide (or, of course, can use whatever time unit desired; mph would be a common US unit for some such calculations but that can be done post facto, too).
  7 件のコメント
Peter Perkins
Peter Perkins 2016 年 12 月 1 日
dpb, a duration represents a fixed length of time, independently of the units in which it's displayed in. So for example
>> isequal(hours(1),minutes(60),seconds(3600))
ans =
1
datetime is the same way about time zones, these two datetimes have different displays but their values are equal:
>> ny = datetime(2016,12,1,12,0,0,'TimeZone','America/New_York')
ny =
01-Dec-2016 12:00:00
>> la = datetime(2016,12,1,9,0,0,'TimeZone','America/Los_Angeles')
la =
01-Dec-2016 09:00:00
>> isequal(ny,la)
ans =
1
There is no double method to do duration->numeric conversion, because it would either have to use some default unit, or (as you suggest) the number that it returns would depend on the display format. Either would be kind of confusing. So to convert duration to numeric, you specify what units you want that number to be in.
dpb
dpb 2016 年 12 月 1 日
編集済み: dpb 2016 年 12 月 1 日
Peter, that's well and good (albeit probably not the way I'd've designed it :) ) but finding it out from the doc is pretty tough...it took me some several minutes of searching links to finally uncover the above page...but the example you give above indicates that the user has to know what the units of the value are; to write the above has the inherent assumption of the numbers are in seconds. I was figuring the general case is the same excepting if one has generated a duration by some mechanism, the magnitude (generally) will have been set by that generation process such as subtracting an origin from a time series or the like. In that case the return value if specify a given format being (for your example above) 1,60,3600 depending on 'hours','minutes','seconds' as the format wouldn't seem that unexpected to me; if fact, not having the class to play with to learn firsthand differently, it seems to me it would be the expected result for assignment just as what you see on display.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by