Given a grid inclined at an angle θ (theta) with equal sized square-shaped cells with indices 00, 01, 02, ..., 55 (where first digit being x index and second being y index, for instance 00 means a cell at the intersection of row 0 and column 0), and a point p(x,y), how can we know that in which grid cell does the point lie without checking all the cells?
For instance, in the image below point p lies in the cell with index 23.
I found one answer at Checking if a point is inside a rotated rectangle that explains how to determine if a point lies inside a rotated rectangle, but with this approach I need to check all the grid cells.
Perhaps the simplest way - rotate point by the same angle (with negative sign) and check new coordinates in axis-aligned grid
nx = x * cos(theta) - y * sin(theta)
ny = x * sin(theta) + y * cos(theta)
row = (int) (ny / cellsize)
col = (int) (nx / cellsize)
I am currently studying experimental designs in statistics and I am calculating values pertaining to 2^3 factorial designs.
The question that I have is particularly with the calculations of the "contrasts".
My goal of this question is to learn how to use the table "Coded Factors" and "Total" in order to get the values "Contrast" using the IF THEN function in Excel.
For example, Contrast A is calculated as : x - y . Where
x = sum of the values in the Total, where the Coded Factor A is + .
And y= sum of the values in the Total, where the Coded Factor A is - .
This would be rather simple, but for the interactions it is a bit more complex.
For example, contrast AC is obtained as : x - y . Where
x = sum of the values in the Total, where the product of Coded Factor A and that of C becomes + .
And y = sum of the values in the Total, where the product of Coded Factor A and that of B becomes - .
I would really appreciate your help.
Edited:
Considering the way how IF statements work, I thought that it might be a good idea to convert the + into 1 and - into -1 to make the calculation straight forward.
Convert all +/- to 1/-1. Use some cells as helper..
Put in these formulas :
J2 --> =LEFT(J1)
K2 --> =MID(J1,2,1)
L2 --> =MID(J1,3,1)
Put
J3 --> =IF(J$2="",1,INDEX($B3:$D3,MATCH(J$2,$B$2:$D$2,0)))
and drag to L10. Then
M3 --> =J3*K3*L3*G3
and drag to M10. Lastly,
M1 --> =SUM(M3:M10)
How to use : Input the Factor comb in cell J1 and the result will be in M1.
Idea : separate the factor text > load the multiplier > multiply Total values with multiplier > get sum.
Hope it helps.
I have location points collected from a garmin device stored in an excel sheet in Degree Minutes format ---
W00208.172,N1046.977
How can I convert it to either Decimal Degrees or Degrees Minutes seconds Format ?
So I was looking for a lazy answer and wasn't happy so gonna put here what I made in the end:
Wanting to convert between these two formats:
33°59'05.5"S 22°39'42.7"E and -33.98485,22.66186
The left being "Degrees Minutes Seconds" and the right being "Decimal"
Of course I have to make some assumptions so they are that it assumes your are following the above formats exactly.
Ok so first is from Degree to Decimal (the source being in cell B2):
=ROUNDDOWN(if(mid(B2,find(" ",B2)-1,1)="S","-","")&mid(B2,1,find("°",B2)-1)+mid(B2,find("°",B2)+1,find("'",B2)-find("°",B2)-1)/60+mid(B2,find("'",B2)+1,find("""",B2)-find("'",B2)-1)/60/60,5)&","&rounddown(if(right(B2,1)="W","-","")&mid(right(B2,find(" ",B2)-1),1,find("°",right(B2,find(" ",B2)-1))-1)+mid(right(B2,find(" ",B2)-1),find("°",right(B2,find(" ",B2)-1))+1,find("'",right(B2,find(" ",B2)-1))-find("°",right(B2,find(" ",B2)-1))-1)/60+mid(right(B2,find(" ",B2)-1),find("'",right(B2,find(" ",B2)-1))+1,find("""",right(B2,find(" ",B2)-1))-find("'",right(B2,find(" ",B2)-1))-1)/60/60,5)
And then from Decimal to Degree (the source being in cell C2):
=abs(ROUNDDOWN(left(C2,find(",",C2)-1))) & "°" & ROUNDDOWN((abs(left(C2,find(",",C2)-1))-abs(ROUNDDOWN(left(C2,find(",",C2)-1))))*60) & "'" & round(((abs(left(C2,find(",",C2)-1))-abs(ROUNDDOWN(left(C2,find(",",C2)-1))))*60- rounddown((abs(left(C2,find(",",C2)-1))-abs(ROUNDDOWN(left(C2,find(",",C2)-1))))*60))*60,1) & """"&if(value(left(C2,find(",",C2)-1))<0,"S","N")& " " & abs(ROUNDDOWN(RIGHT(C2,len(C2)-find(",",C2)))) & "°" & rounddown((abs(RIGHT(C2,len(C2)-find(",",C2)))-abs(ROUNDDOWN(RIGHT(C2,len(C2)-find(",",C2)))))*60) & "'" & round(((abs(RIGHT(C2,len(C2)-find(",",C2)))-abs(ROUNDDOWN(RIGHT(C2,len(C2)-find(",",C2)))))*60- rounddown((abs(RIGHT(C2,len(C2)-find(",",C2)))-abs(ROUNDDOWN(RIGHT(C2,len(C2)-find(",",C2)))))*60))*60,1) & """"&if(value(right(C2,len(C2)-find(",",C2)))<0,"W","E")
If only you could have variables in formulae... most of that is duplicate formulae with some simple enough rules...Anyway, hope it helps someone.
The range of longitude (E or W) is -180 to 180, so 3 digits
The range of latitude (N or S) is -90 to 90, so 2 digits
Take "W00208.172", take the first 3 digits and store it to degress:
deg = 002
Then take the rest as decimal minutes:
min = 08.172
Now convert to decimal degrees (DEG):
decDegrees = deg + min / 60.0
Same for latitude: except that degrees are now only 2 digits
N1046.977: Take 10 degrees, and 46.977 minutes.
For both think if you want to keep the "W" symbol:
Often it is better to mutiply with -1 in case of of "W" or "S", do this as last step in your conversion!
Negative decimal degrees means W (for longitude) or S (for latitude).
For your provides coordinates that means:
lat: North 10046.977 = 10 + 46.977 / 60 = 10.78295;
lon: (2 + 8.172 / 60) * -1 = -2.1362;
so that location should be in Burkina Faso, 15m near a road (= plausible) 5,52 km south east east of Dununuai
This formula works on Google Sheets for converting from the format 018°40.1333 to 18.66888833 and -34°01.0597 to -34.01766167
=IF(MID(B2,1,1) = "-", (INT(MID(B2, 1, SEARCH("°", B2) - 1)) - MID(B2, SEARCH("°", B2) + 1, len(B2))/60), (INT(MID(B2, 1, SEARCH("°", B2) - 1)) + MID(B2, SEARCH("°", B2) + 1, len(B2))/60))
I have the following excel setup that is extremely massive but here is a simplified setup:
Site1 X-Given Y-Given Site2 X-New-Given Y-Interpolated
A 10 400 A 25 550
A 20 500 A 25 550
A 30 600 A 26 560
A 40 700 B 27 570
A 50 800 B 30 600
B 10 400 B 15 450
B 20 500 B 25 550
B 30 600 B 30 600
What I'm trying to accomplish is to have each Y-Interpolated only interpolate based upon its specific site and not have any cross over. So site A would only interpolate with site A, and same with site B... so on and so forth.
I'm using the interpolate excel addin which has the following syntax:
=interpolate(x_array,y_array,x_given)
Thanks for the help!
You could try this worksheet function alternative... with data in A1:E9, enter this in F2 and fill down:
=FORECAST(E2,IF(MMULT(ROW(B$2:B$9)-LOOKUP(0,(B$2:B$9>=E2)/(A$2:A$9=D2),ROW(B$2:B$9))-0.5,1)^2<1,C$2:C$9),B$2:B$9)
Update: Here's a slightly shorter alternative entered with CTRL+SHIFT+ENTER
=PERCENTILE(IF(A$2:A$9=D2,C$2:C$9),PERCENTRANK(IF(A$2:A$9=D2,B$2:B$9),E2,20))
This assumes a positive relationship between variables and returns values at both boundaries.
Background
If you're going to use worksheet functions for this, the obvious approach is to find the neighboring two points to X: (X1,Y1) and (X2,Y2). Then calculate Y using:
Y = Y1 + (X - X1) * (Y2 - Y1) / (X2 - X1)
The problem is that this leads to a lengthy formula involving six INDEX/MATCH combinations and six more conditions for restricting data to the specified site. This leads one to look for other options...
1. The first formula looks complicated but all it's doing is applying a straight line fit based on the two neighboring points for the same site. Evaluating the formula for the third row above - by highlighting each part of the formula and pressing F9 - gives:
=FORECAST(26,{FALSE;500;600;FALSE;...},{10;20;30;40;...})
FORECAST ignores non-numeric data so the result is the same as just using {500,600} and {20,30} for the 2nd and 3rd arguments. You can use F9 on other parts of the formula to break it down further - I'll leave details to you. (The MMULT(...,1) part just changes the argument to an array so you can enter the formula without array-entry.)
2. The second formula is easier to follow. First note that in Excel percentiles are calculated by linear interpolation and the IF part is just restricting the numeric data to the specified site. Assuming data is increasing it follows that we can find the k-value in the PERCENTILE formula that matches the lookup value in the x-range and return the y-range value with that k-value. For the example in question:
26 =PERCENTILE({10,20,30,40,50},0.4)
560 =PERCENTILE({400,500,600,700,800},0.4)
To calculate the value of 0.4 the PERCENTRANK can be used which is inverse to PERCENTILE:
0.4 =PERCENTRANK({10,20,30,40,50},26)
0.4 =PERCENTRANK({400,500,600,700,800},560)
The formula above follows by combining these two functions, the last argument is set to 20 for full precision (Excel stores values internally to around 15-17 digits of precision).
Because the tool that you're using is based on a .xll add in for excel, you(or we) can not modify the code or create a custom version of interpolate that allows adding conditions.
Instead, you'll have to filter your data apart and then run the custom-function on the filtered datasets.