Vector Length in MapInfo - vector

Does anyone know how to calculate the exact length of a vector in MapInfo?
Thanks.

I believe you can use
Dim vector_length As Float
vector_length = ObjectLen(Obj, "m")

I would prefere to use CartesianObjectLen instead of ObjectLen
CartesianObjectLen vs ObjectLen
dim o as object
select * from TABLE where Unique Column = Unique Code into sel
o=sel.obj
print(CartesianObjectLen(o, "m"))

Related

Julia beginner: Iterate getindex() for increasing indices

I'm working with a 121x137 (i,j) array (mortality table) and am trying to create a 121x1 vector from this made up of the (i+1,j+1) values (i.e. index (50,50), (51,51) and so forth.
I'm using the following code - BaseTable is my 121x137 array:
age=50
survivalcurve = for i in age:nrow(BaseTable)-1
for j in age:ncol(BaseTable)-1
println(getindex(FemaleBaseTable, i+1, j+1))
end
end
However, when I do this, its returning all values of i and j - if I picture the values I want as a diagonal line running top-bottom, L-R of my table, its giving me all the values on the top right of my imaginary diagonal line.
If I fix i and loop through j, it works and returns the entire 50th row:
age=50
survivalcurve =
for j in age:ncol(FemaleBaseTable)
println(getindex(FemaleBaseTable, 50, j+1))
end
and likewise if I fix j and loop through i, this works and returns the entire jth column:
age=50
survivalcurve =
for i in age:nrow(FemaleBaseTable)-1
println(getindex(FemaleBaseTable, i+1, 50))
end
I've surmised its returning all values because I'm using age:nrow / age:ncol, but not sure what a suitable replacement would be to only return the (i+1),(j+1) value would be. Any help would be appreciated!
You can collect the diagonal elements starting at any index (i,j) by using either diag from LinearAlgebra.jl or manually using a single loop.
Assuming you have:
nrows, ncols = 121, 137
FemaleBaseTable = rand(nrows, ncols)
# And the diagonal should start at any (i,j)
i, j = 50, 50
You can either use
diag(#view FemaleBaseTable[i:end,j:end])
or,
[FemaleBaseTable[i,i] for (i,j) in zip(i:nrows,j:ncols)]

How to Flag Floats in a vector of Floats and Chars in Julia

I have a mixed vector of floats and characters that I'm streaming from a text file. This vector is being read in as a string. My problem is that I want to parse only the floats and ignore the characters. How can I do this?
v = "Float_or_Char"
if isblank(v) == false # <-- v might be blank as well
Parse(Float64,v) # <-- only if v is a Float (how do I do this?)
end
Supposing x is a vector of strings, some of which are floats-as-strings and the rest are actual strings, you could do something like
for i in 1:length(x)
f = NaN
try
f = float(x[i])
println("$i is a float")
catch
println("$i isn't a float")
end
end
If you are using Julia 0.4 (not yet released), you could get really fancy if you just wanted the floats from x using the new Nullable type and the new method tryparse
maybe_floats = map(s->tryparse(Float64,s), x)
floats = map(get, filter(n->!isnull(n), maybe_floats))

scilab submatrix incorrectly defined

I am stuck at creating a matrix of a matrix (vector in this case)
What I have so far
index = zeros(size(A)) // This is some matrix but isn't important to the question
indexIndex = 1;
for rows=1:length(R)
for columns=1:length(K)
if(A(rows,columns)==x)
V=[rows columns]; // I create a vector holding the row + column
index(indexIndex) = V(1,2) // I want to store all these vectors
indexIndex = indexIndex + 1
end
end
end
I have tried various ways of getting the information out of V (such as V(1:2)) but nothing seems to work correctly.
In other words, I'm trying to get an array of points.
Thanks in advance
I do not understand your question exactly. What is the size of A? What is x, K and R? But under some assumptions,
Using list
You could use a list
// Create some matrix A
A = zeros(8,8)
//initialize the list
index = list();
// Get the dimensions of A
rows = size(A,1);
cols = size(A,2);
x = 0;
for row=1:rows
for col=1:cols
if(A(row,col)==x)
// Create a vector holding row and col
V=[row col];
// Append it to list using $ (last index) + 1
index($+1) = V
end
end
end
Single indexed matrices
Another approach would be to make use of the fact an multi-dimensional matrix can also be indexed by a single value.
For instance create a random matrix named a:
-->a = rand(3,3)
a =
0.6212882 0.5211472 0.0881335
0.3454984 0.2870401 0.4498763
0.7064868 0.6502795 0.7227253
Access the first value:
-->a(1)
ans =
0.6212882
-->a(1,1)
ans =
0.6212882
Access the second value:
-->a(2)
ans =
0.3454984
-->a(2,1)
ans =
0.3454984
So that proves how the single indexing works. Now to apply it to your problem and knocking out a for-loop.
// Create some matrix A
A = zeros(8,8)
//initialize the array of indices
index = [];
// Get the dimensions of A
rows = size(A,1);
cols = size(A,2);
x = 0;
for i=1:length(A)
if(A(i)==x)
// Append it to list using $ (last index) + 1
index($+1) = i;
end
end
Without for-loop
If you just need the values that adhere to a certain condition you could also do something like this
values = A(A==x);
Be carefull when comparing doubles, these are not always (un)equal when you expect.

big negative number - postive giving postivie only

I have temp2 value -52340.0 and hslColor.Luminosity is 240.0
When Dim temp1 As Double = (hslColor.Luminosity - temp2). It shoud give -ve number but I am getting always positive number.
results should nbe -52100, but I am getting +52100. How to handle this?
240 - (-52340) = 52580
Do you remember what happens if you subtract a negative?
This is what you are doing:
Dim temp1 as Double = (240 - -52340.0)
You are subtracting a negative.
results should nbe -52100, but I am getting +52100.
That's a lie. You should be getting 52580, not 52100.
If you substitute the values in like this:
240 - -52340
You're subtracting a negative, so it's the same as adding a positive:
240 + 52340
Which equals 52580.
How to handle this?
To get the intended result of -52100, either use this if temp2 is always negative:
Dim temp1 As Double = (hslColor.Luminosity + temp2)
or use this, if you need to subtract the absolute value of temp2, whether it can be negative or positive:
Dim temp1 As Double = (hslColor.Luminosity - Math.Abs(temp2))
Dim temp1 As Double = (240 - -52340)
the answer will be 52580
Dim temp1 As Double = (240 - 52340)
the answer will be -52100

How to find original values back from the final result output of the sequential Xor procedures?

The problem is that I want to get the original values of B, or the original value of C or A. Here is the code:
Dim strA As String = "A"
Dim strB As String = "B"
Dim strC As String = "C"
Dim result As Byte = 0
' Fetch the byte character code of strings and Xor them all into the result in a sequence.
result = result Xor AscW(strA)
result = result Xor AscW(strB)
result = result Xor AscW(strC)
' the final result value is 64
How to do this? Please help me with the correct solution to this problem. If there can be another parameter which when applied with a formula may reveal the original values: "A", "B", "C". Thank you.
If I understand your question correctly, this is simply not possible. There are multiple ways to split result back into strA, strB and strC.
To make it easier to see why, consider addition instead. Suppose you start with A = 5, B = 6 and C = 7. The sum is 18. Now suppose you start with A = 1, B = 1 and C = 16. The sum is still 18. Bottom line: if all you have is "18" there's no way to split it back, because multiple inputs give the same output.

Resources