Sign in to follow this  
Followers 0
noorloai

array in studio5000

4 posts in this topic

Hi All,

I have two DINT array for example array1 [200] = [ 0, 1.........199], array2[100] = [ 20,40,60 ...180]

 array1[30] = 30 need to compare it with array2[100]  and find the closest range.

in my example array1[30] is between array2[0] and array2[1] how can I do that in studio5000?

I haven't worked with array before and therefore your support is appreciated 

Thanks

 

Share this post


Link to post
Share on other sites

I can think of some brute force ways to do it with loops, depending on what you want to do with the outcomes.

Are the values in the arrays changing dynamically? Are the values in Array2 always in ascending order? What do you want to do with the information once you have it? In other words, do you need to continuously step through all 200 values of array 1 to see where they fit in array 2?


 

Share this post


Link to post
Share on other sites

well, the value in array 1 changes dynamically, but in array 2 is not. and its ascending order.

I want to check the array 1 element value with array 2 values and get the closest bigger  number in array 2 so I can update my target to the closest number  and repeat that for each element in array 1

example:

target position =0 

current array[1] = 20000,

compare with the constant array 2 , which is between 18000 and 25000 values

then take the closest bigger number and move it to the target position 

 

Share this post


Link to post
Share on other sites

Not a huge fan of this, but it seems to work to look up a single array element. This may not work well for rapidly changing values.

Lookup1.thumb.PNG.e0cbc2afd966697c8d359c

The LIM instruction makes sure the value to be looked up is within the range of values stored in the array.

I think I like this method better:

Lookup2.thumb.PNG.82f493fe5e09f93c8c024d

Both methods take about 100 PLC scans to search the array. If you need it to update in one PLC scan, you'll need to use a JMP/LBL pair:

Lookup3.PNG.f10b2b001a0dc1048c4d26617857

You will need either one rung per element in array1 or add an outer loop to index through the array1 elements in a similar way that this loops through the array2 elements.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0