I am trying to show the location coordinates in specific format like 42° 51’36.712032" N, 112° 25’ 45.069804" W (example of geographical coordinates). How can i implement this.
Thanks in advance.
From Wikipedia:
Each degree of longitude is sub-divided into 60 minutes, each of which is divided into 60 seconds. A longitude is thus specified in sexagesimal notation as 23° 27′ 30" E. For higher precision, the seconds are specified with a decimal fraction.
Thus, take the fractional part of your coordinate and multiply it by 3600 (60×60) to get the total number of seconds; to convert that to the minutes/seconds that you want, take the total seconds mod 60 to get the actual seconds, subtract that number from the fractional part you got earlier, and then divide the result by 60 to get the number of minutes.
Related
Using a PostgreSQL database, what is the best way to store time, in hours, minutes and seconds. E.g. "40:21" as in 40 minutes and 21 seconds.
Example data:
20:21
1:20:02
12:20:02
40:21
time would be the obvious candidate to store time as you describe it. It enforces the range of daily time (00:00:00 to 24:00:00) and occupies 8 bytes.
interval allows arbitrary intervals, even negative ones, or even a mix of positive and negative ones like '1 month - 3 seconds' - doesn't fit your description well - and occupies 16 bytes. See:
How to get the number of days in a month?
To optimize storage size, make it an integer (4 bytes) signifying seconds. To convert time back and forth:
SELECT EXTRACT(epoch FROM time '18:55:28'); -- 68128 (int)
SELECT time '00:00:01' * 68128; -- '18:55:28' (time)
It sounds like you want to store a length of time, or interval. PostgreSQL has a special interval type to store a length of time, e.g.
SELECT interval'2 hours 3 minutes 20 seconds';
This can be added to a timestamp in order to form a new timestamp, or multiplied (so that (2 * interval'2 hours') = interval'4 hours'. The interval type seems to tailor-made for your use case.
I need to get a timestamp in integer seconds, that won't roll over.
Can be elapsed CPU seconds, or elapsed clock or epoch seconds.
'clock' gives a date/time vector in years ... seconds.
But I can't figure out how to convert this to integer seconds.
cputime returns elapsed integer seconds but "This number can overflow the internal representation and wrap around.".
What about round(3600 * 24 * now)?
According to the manual, now returns the number of days since the year 0, as a floating point number. Multiplying by 86400 should thus give seconds.
Usually it is better to use a fixed-point format for keeping track of time, but since you are only interested in integer seconds, it should not be too much of a problem. The time resolution of now due to floating point resolution can be found like this:
>> eps(now*86400)
ans =
7.6294e-06
Or almost 8 microseconds. This should be good enough for your use case. Since these are 64-bit floating point numbers, you should not have to worry about wrapping around within your lifetime.
One practical issue is that the number of seconds since the year 0 is too large to be printed as an integer on the Matlab prompt with standard settings. If that bothers you, you can do fprintf('%i\n', round(3600 * 24 * now)), or simply subtract some arbitrary number, e.g. to get the number of seconds since the year 2000 you could do
epoch = datenum(2000, 1, 1);
round(86400 * (now - epoch))
which currently prints 488406681.
I have two sets of time series data which are collected with different time intervals. One is measured every 15 minutes and the other every 1 minute.
The measured variables are oxygen concentration, oxygen saturation and time, all three of which are measured using the two different instruments which have the different time intervals (6 column arrays in total).
I have two times between which I want to find the index's of all the entries at 15 minute intervals in the time column that sit between them.
co=1;
for i = datenum('03/11/2014/10/00/00','dd/mm/yyyy/HH/MM/SS'):datenum('03/11/2014/00/15/00','dd/mm/yyyy/HH/MM/SS')-datenum('03/11/2014/00/00/00','dd/mm/yyyy/HH/MM/SS'):('03/11/2014/16/00/00','dd/mm/yyyy/HH/MM/SS');
u=find(xyl_time==i);
New_O2(co,1)=xyl_o2conc(u);
New_O2(co,2)=xyl_o2sat(u);
v=find(sg_time==i);
New_O2(co,3)=sg_o2conc(v);
New_O2(co,4)=sq_o2sat(v);
co=co+1;
end
however, this does not work. I have narrowed it down and its something to do with the time interval that I'm using. I want it at every 15 minutes, but when I produce the 15 minute interval and then datestr that number, it comes up with '12:15AM'. I think this is causing the problem, but have no idea how to produce just times alone i.e I just want 00:15 not 12:15 not 00:15 AM or PM. just spacings of 15 minutes for my for loop.
How to calculate the time taken to travel between two points in the map view.
Measured Travel Time
You can only do that if you have the timestamp stored together with the coordinates of the points. Other solutions are unrealistic. If you have both timestamps, then it is simple to calculate the difference in number of seconds.
Convert both times to "timeSinceReferenceDate" and subtrac:
something like deltaSeconds = abs(t2 - t1);
Estimated Traveltime automotive
If you have only coordinates, and want to know the estimated travel time by using a car, you have to use a routing service, which calculates the route and time duration for your you.
Given a BPM (beats per minute) MIDI delta time (leftmost bit off) with speed of 192:
0x00C0
I want to convert it to a FPS/TPM (frames per second / ticks per minute) delta time (leftmost bit on), but it should be the same (or the most accurate) speed value if you know what I mean.
For more info about MIDI Delta Time please take a look at Midi File Format under Header Chunk -> Time Division.
I am looking for a formula that will convert between these two deltatime types.
If you're talking about 0x00C0 being the time division field, what you're referring to is not 192 beats per minute, but rather 192 ticks per beat, quite a different beast. BPM is specified indirectly via "Set Tempo" events, given in microseconds per beat (with the lamentably ubiquitous 120 BPM being assumed to begin with). The trickiness of time division with this format is that the length of a tick will grow and shrink depending on the tempo changes in the song.
Let's say the time division you want to convert to has F as the frames per second (24, 25, 29.97, or 30) and G as the ticks per frame (note: it's not ticks per minute!). Further, let's assume that the current tempo in microseconds per beat is p. Then the formula to convert a given duration in ticksold to ticksnew (the unit analysis really helps!) is:
y = x ticksold * (1/192) beat/ticksold * p μsec/beat * (1/106) sec/μsec * F frames/sec * G ticksnew/frame
= ((x * p * F * G)/(192*106)) ticksnew