LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

program to get all the asked subset given a set

Hello,

 

The included VI searches for the first subarray I want to find in the given array and adds one element. I want to get ALL the subarrays(+1) that match the giving subarray in the array. How could I adapt the program to obtain this?

0 Kudos
Message 1 of 5
(2,105 Views)

Hi iron,

 

use one more loop around your code to repeat the operation!

 

More hints:

- use better labels for "numeric" and "numeric 2". "start search" and "found index" would be nice.

- keep the search index in a shift register of that additional loop

- it would help to put your comments in English rather than in Dutch…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,072 Views)
  • It would help if you could fill typical default data into all controls before attaching the VI. How big are the arrays?
  • You have a problem with representation. "numeric 2" should be blue, same for "numeric), but give them a reasonable name first as has been mentioned.
  • It is not clear what you mean by "adds one element" are you talking about a mathematical addition (+) or appending? (Sorry, I don't know dutch). In either case, "array subset" always makes an array smaller, i.e. the opposite.
  • All the subarrays that match are identical so there is a lot of redundancy. Do you just want to know how many matches there are?
  • Where does the data come from. I assume you are aware that equal comparisons on floating point data can be very dangerous and will probably not work unless the array values come from the same source or are actually integers.
0 Kudos
Message 3 of 5
(2,062 Views)

Let me give some context:

The idea is that the user is going to play a game against the computer. There are three choices: 0,1 and 2. 0 beats 1, 1 beats 2 and 2 beats 0; the rest are equal.

The computer has to make a reasonable guess, if possible . He has to look the three last moves the player made (all the moves will be stored in an array) and has to look this up in the players history. If he finds this combination, he has to make the choice that beats the choice the user is expected to make (the one following in the history). If he does not, he has to repeat the process with the last 2 moves. If the result is the same, he makes  a random choice.

This was no problem if the combination has been made once. But else, I need all the choices the user made ond choose the most frequent. 

 

As I'm only a beginner in Labview, this code in Python would look like:

def array(array,subarray):
alist=[]
for i in range(0,len(array)-1):
if array[i]==subarray[0]:
if array[i+1]==subarray[1]:
if array[i+2]==subarray[2]:
alist.append(array[i+3])
if alist==[]:
for i in range(0,len(array)):
if array[i]==subarray[1]:
if array[i+1]==subarray[2]:
alist.append(array[i+2])
return alist


array([0,1,0,2,2,0,1,2,0,1,1,2,0,1,2,0,0,1,1,1,2,0,2,0,1,2,0,1,2,0,1,2],[0,1,1]) #gives [2,1]

 

0 Kudos
Message 4 of 5
(2,050 Views)

Hi iron,

 

that's a nice task to LEARN LabVIEW…

 

If he finds this combination, he has to make the choice that beats the choice the user is expected to make (the one following in the history).

That's the part you were asking about before.

The solution is:

1. program the search part (already done by you, but take Christian's suggestions)

2. repeat the search for the whole array: use a loop!

 

But else, I need all the choices the user made ond choose the most frequent.

- The word "else" implies a case structure ("IF condition THEN do something ELSE do other")

- For choosing the "most frequent" you need to count each selection: use a loop with some shift registers. (Or choose the easy way with a histogram function.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(2,026 Views)