필터 지우기
필터 지우기

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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by