04-22-2018 04:43 AM
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?
04-22-2018 11:09 AM
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…
04-22-2018 12:48 PM - edited 04-22-2018 12:51 PM
04-22-2018 03:28 PM
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]
04-23-2018 12:57 AM
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.)