05-05-2020 05:00 AM
Hi to everyone,
I have a problem.
Starting from 2 arrays I would like to split one based on the values of the second one.
Ex. A= [ 1 2 3 4 5 6 7 8 9 10] B = [ 3 8 ]
Result arrays wanted: C = [ 1 2 3] D= [ 4 5 6 7 8] E=[ 9 10 ]
The lengths of the two array are variable.
Do you have any suggestions?
Thank you so much in advance.
Rebecca
Solved! Go to Solution.
05-05-2020 05:07 AM
Hi Rebecca,
@RebeccaCasadio wrote:
Starting from 2 arrays I would like to split one based on the values of the second one.
Ex. A= [ 1 2 3 4 5 6 7 8 9 10] B = [ 3 8 ]
Result arrays wanted: C = [ 1 2 3] D= [ 4 5 6 7 8] E=[ 9 10 ]
Do you have any suggestions?
And what are the specification for splitting array A? What should be done with those values from array B?
I guess you want to split array A when there is an element "3", then split again for an element "8" and then keep the remaining elements.
What happens when the element from array B is not found in array A?
What happens when array B contains a "3", but array A contains either "2.9999" or "3.0001"?
So provide a clear (and senseful) description of the requirements and you are halfway done with solving your problem… 😄
05-05-2020 05:33 AM
Hi,
I simplified the question.
In the real program that I'm writing:
- I have one array containing the latitude coordinates of a route: array A.
- I have an array B where there are one or more latitudes of the route (latitude coordinates in this array are not identical to the ones in array A, this is why I need to make a comparison).
What I want to do is to compare the latitude coordinates of A with the ones in B and if their difference is lower than a threshold of 5*10^-6, I want to split the array A according to the latitude coordinates stored in array B.
What happens when the element from array B is not found in array A? Array A remains whole, so it is not divided.
I guess you want to split array A when there is an element "3", then split again for an element "8" and then keep the remaining elements. Right
What should be done with those values from array B? After using the array values, they are no longer used. So they are only useful for understanding how to divide array A.
I hope I’ve made myself clear.
Thanks
Reb
05-05-2020 05:45 AM - edited 05-05-2020 05:48 AM
Hi Rebecca,
@RebeccaCasadio wrote:
What I want to do is to compare the latitude coordinates of A with the ones in B and if their difference is lower than a threshold of 5*10^-6, I want to split the array A according to the latitude coordinates stored in array B.
So you want to do:
FOR i := each element in array B
difference := arrayA - B[i]
boolArray := (difference <= 5u)
index := Search1DArray(boolArray, TRUE)
IF index >= 0 THEN
arrayA1 := ArraySubset(arrayA, 0, index+1)
arrayA := ArraySubset(arrayA, index+1)
ENDIF
NEXT
See how far you get with your homework stuff! 😄
(You need an autoindexing FOR loop with a shift register, some simple math/comparison, a case structure, some basic array functions…)
Hint: as your subarrays will/can have different length you should learn about using arrays of clusters of arrays!
05-05-2020 05:52 AM
Yes, exactly 🙂 Thank you for the answer.
My problem was (and I think is) in the implementation. But I will try.
Thanks for your availability.
Reb