How to split these coordinates to degrees, minutes and seconds?
E0732931.00 and N30 2025.20
Is it 73 degrees, 29 mins and 31 seconds. To convert it to decimal degree, i have to
73+39/60+31/3600?
N30 2025.20 is 30 degs, 20 minutes, 25 seconds? What is the value after the decimal?
2nd i want to ask that is there any coordinate system which uses 100 seconds in a minute, i.e.
decimal degrees = 73+39/60+31/(60*100) ???
Your asumption are correct.
Further:
What is the value after the decimal?
the fraction of seconds: so 25.20 seconds
is there any coordinate system which uses 100 seconds in a minute, i.e.
No! There are other systems like DM which uses Degrees and decimal minutes: e.g 23 deg 17.1234 minutes
Related
I have to interpolate wind directions. The data is given for every 1000 [ft]. for example:
%winddata input in feet en degrees
x=0:1000:10000;
grad=[340 350 360 1 10 20 30 35 34 36 38];
The interpolation works great, i use the function interp1. (please see code below.) However, the step from 360 degrees to 1 degrees is a problem. I want Matlab to interpolate from 360 to 1 degree directly (clockwise), instead of anticlockwise with the values degreasing from 360-359-358-...3-2-1. That doesnt make sense when you interpolate wind directions.
How can i command Matlab to repeate the x-axis and values every 360 degrees?
clear all;clc;
h=2000;
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 1 10 20 30 35 34 36 38];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
yinterp1 = interp1(x,degrees,u,'linear');
figure(3)
plot(degrees,x,'bo',yinterp1,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'
The problem is that Matlab, as smart as it is, doesn't realise that you're working with degrees, so therefore it sees no reason that 360 = 0. Therefore I believe your problem isn't with finding a way to repeat the plot every 360 degrees, but rather with the data you are feeding in to your interp1 function, as currently you are telling it there is a straight line between the points (0, 950) and (360, 750).
The easiest, but ugliest, method would be to just add 360 to your lower values, so your degrees vector read:
degrees = [340 350 360 361 370 380 390 395 394 396 398];
and then subtract 360 from your degrees and yinterp1 vectors:
clear all;clc;
h=2000;
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 361 370 380 390 395 394 396 398];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
yinterp1 = interp1(x,degrees,u,'linear');
figure(3)
plot(degrees-360,x,'bo',yinterp1-360,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'
xlim([-180 180]);
The obvious problem with this is it isn't able to be applied for all cases, but if you just need a one off, then it works well.
For a more generic solution you could have it so you manually enter a point below which values have 360 added to them:
clear all;clc;
h=2000;
% --------------------- Manual cutoff for rectification -------------------
limitDegrees = 180;
% -------------------------------------------------------------------------
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 1 10 20 30 35 34 36 38];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
indecesTooSmall = find(degrees <= limitDegrees);
oneVec = zeros(size(degrees));
oneVec(indecesTooSmall) = 1;
vecToAdd = 360*ones(size(degrees));
vecToAdd = vecToAdd .* oneVec;
newDegrees = degrees + vecToAdd;
yinterp1 = interp1(x,newDegrees,u,'linear');
figure(3)
plot(newDegrees-360,x,'bo',yinterp1-360,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'
xlim([-180 180]);
Both of the above solutions give the following:
EDIT: Substantially easier solution, just use rad2deg(unwrap(deg2rad(degrees))), or try to find an unwrap which works for degrees.
I'm converting coordinates from degrees minutes seconds to decimal degrees. However, in the process of converting, the resulting coordinates are much more precise than they should be.
How can I correctly incorporate the lack of precision?
For example, some coordinates lacking seconds:
143 DEG 10 MIN W, 28 DEG 25 MIN N
To convert, I would do the following:
143.1667 <- 143 + 10/60
28.41667 <- 28 + 25/60
But really, the longitude could be anywhere from:
143.1667 <- 143 + 10/60 + 0/3600
to
143.1831 <- 143 + 10/60 + 59/3600
It seems like I should be rounding these coordinates so that they do not convey artificial precision...
You can round it just like this:
double roundedValue = Math.floor(unroundedValue * 10) / 10;
// 123.456 --> 123.4
If you use "100" instead of "10", you will get a a precision of two digits.
My code is like below:
I have actually two Questions regarding my code:
1:From this code i want to find the value of D.Even I get the value of "D" but every time current "D" add up with previous "D". Like get
D(1,:)=30 30 30 30 30
D(2,:)=60 60 60 60 60
D(3,:)=89 89 89 90 90
But i want to get
D(1,:)=30 30 30 30 30
D(2,:)=30 30 30 30 30
D(3,:)=29 29 29 30 30
I know i can do this by extracting the current D from the previous D after getting the for loop but i do not want to do this.I want to do something within the for loop.
Another question is i need to run this code for iteration=100 times and i need to store the value of "D" for every trial in a cell array, because later i need to use those values of D.
Matlab experts need your help and suggestion for two questions.
First part: after the loop do this
D = [D(1,:), diff(D)];
e.g.
D = [30 30 30 30 30
60 60 60 60 60
89 89 89 90 90];
[D(1,:); diff(D)]
ans =
30 30 30 30 30
30 30 30 30 30
29 29 29 30 30
Second part: why just store it in a new matrix?
AllTheDs{counter} = D %// This will be outside your current for-loop but presumably inside your new loop that counts to 20k
My first thought was also the diff solution as proposed by #Dan. However then I started wondering whether the problem was perhaps that you just keep adding things without the intention to do so.
I see you have this as the only line where rec2_Wopt is updated
rec2_Wopt(1) = rec2_Wopt(1) + sum(RecP) ;
Hence it is logical that after the second loop, it will include the additions of the first loop and the second loop.
To solve this, start each loop by resetting your variables. For this variable it would be:
rec2_Wopt(1) = 0
Or
rec2_Wopt = zeros(1, length(N)) ;
i want create a counter that retrieve the number of month, day, hour, minute from a given number in minutes, for example i know that:
60 minutes in an hour
24 hours in a day = 60 x 24 = 1440 minutes
31 days per month
1 month = 24 x 60 x 31 = 44,640 minutes
so if i give for example the number 44640 i want have 1 month 0 day 0 hour 0 minute , or for example if i give 44700 i want have 1 month, 0 day 0 hour 60 minute or 1 month 0 day 1 hour 0 minute
any help please?
int total_minutes = 44640;
int total_hours = total_minutes / 60;
int minutes = total_minutes % 60;
int total_days = total_hours / 24;
int hours = total_hours % 24;
int months = total_days / 31;
int days = total_days % 31;
printf("%d months, %d days, %02d:%02d\n", months, days, hours, minutes);
But that's misleading, since months are not all 31 days. On average, a month in the Gregorian calendar is 30.436875 days (43829.1 minutes), so you could use that figure. For many applications, such calculations just assume that a month is always 30 days. But if your time interval is anchored to a specific point in time, it might be better to use the date at both ends to determine how many whole months there are between them.
Is there any useful module on CPAN that returns number of biggest fractions of date interval, i.e. return integer number of years/months/days/hours/minutes/seconds between two dates, to use in sentence like "N days ago" or "M months ago"
DateTime and DateTime::Duration are the best modules:
use strict;
use warnings;
use DateTime;
use DateTime::Duration;
use Data::Dumper;
my $dt1 = DateTime->now;
my $dt2 = DateTime->new(
year => 2001,
month => 01,
day => 01
);
my $duration = $dt1 - $dt2;
print Dumper($duration);
produces:
$VAR1 = bless( {
'seconds' => 38,
'minutes' => 181,
'end_of_month' => 'wrap',
'nanoseconds' => 0,
'days' => 20,
'months' => 110
}, 'DateTime::Duration' );
You can format absolute times and durations using the sister modules DateTime::Format and DateTime::Format::Duration.
Well, not very difficult to write your own.
Calculate relative time in C#
Time::Duration seems to be a natural choice for what you try to accomplish. I haven't tried it though. Only caveat seems to be that it already gives you phrases like "M months ago", so you might need to parse its output for non-English output.
You might take a look at the Time::Ago module on CPAN (I'm the author). It's a Perl port of the time_ago_in_words() helper from Rails.
Given a duration, it returns a readable string approximation. From the Rails docs:
0 29 secs
less than a minute
30 secs 1 min, 29 secs
1 minute
1 min, 30 secs 44 mins, 29 secs
[2..44] minutes
44 mins, 30 secs 89 mins, 29 secs
about 1 hour
89 mins, 30 secs 23 hrs, 59 mins, 29 secs
about [2..24] hours
23 hrs, 59 mins, 30 secs 41 hrs, 59 mins, 29 secs
1 day
41 hrs, 59 mins, 30 secs 29 days, 23 hrs, 59 mins, 29 secs
[2..29] days
29 days, 23 hrs, 59 mins, 30 secs 44 days, 23 hrs, 59 mins, 29 secs
about 1 month
44 days, 23 hrs, 59 mins, 30 secs 59 days, 23 hrs, 59 mins, 29 secs
about 2 months
59 days, 23 hrs, 59 mins, 30 secs 1 yr minus 1 sec
[2..12] months
1 yr 1 yr, 3 months
about 1 year
1 yr, 3 months 1 yr, 9 months
over 1 year
1 yr, 9 months 2 yr minus 1 sec
almost 2 years
2 yrs max time or date
(same rules as 1 yr)
CPAN module
Repository
[This isn't really an answer, but I think it's relevant.]
If you're going to get into date/time manipulation and calculation, you're best off keeping to the DateTime family of modules. Not only do they have the best handling of timezones that I've found, but they all work with each other. I've never had a problem in this domain which I couldn't find a module in DateTime to solve it.