LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1D array value search

Solved!
Go to solution

Hi,

Below is the list of binary data that i need to compare with one binary data which is (1000010000100001). If  1000010000100001 is present in the below data it has to return true, else it has to return false. 

 

1000000100100100   100100000100001   1100001000010   10010010000001
1000000101000010   100100000010010   1100000100100   10010000011000
1000001000010100   100000110000010   1001001001000   10100001000001
1000001001000000   100000100101000   1001010000100   10100000010100
1000010000100000   100001010000001   1010010000010   10000101001000
1000010000010010   100001000011000   1010000101000   10000110000100

 

can i please know how do I get all the values in a 1D array from the above database and compare (1000010000100001) with each value int he database. 

0 Kudos
Message 1 of 7
(3,169 Views)

unfortunately words are important.

do you really want to import data from a database, or do you have a file, from which you want to import?

 

from a file you could use "Read Delimited Spreadsheet.vi" to get your data into an array, then you use the "Search 1D Array" to find your token.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 2 of 7
(3,164 Views)

since the above binary are limited  I wanted to type values in a file and compare the binary data if it is present in the file.

 

I tried "Read Delimited Spreadsheet.vi". please see the attached image.

 

What it does is it compares only the first value of the row of a file. 

 

here I have two files. Binary.csv and Binary1.csv. 

 

Binary.csv has all the binary file. 

 

Binary1.csv file has only one binary value (1000010000100001). 

0 Kudos
Message 3 of 7
(3,158 Views)

You need to 1st use Reshape array after reading the file to transform is to a 1D array, then you can use the Search 1D array function.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 7
(3,143 Views)

You should additionally be aware you have 3 different end conditions for your For loop, which I would bet almost anything isn't what you want.

 

The loop will stop whenever any of them is finished - in this case, it will iterate once for the value from the binary1.csv file, with only one value in the array.

 

You want to get rid of the constant 10, and if you know that the value you want to match is always one value, just make that value NOT auto-indexing. If you want to compare two lists of numbers and find matches, and you're ok with a brute force approach, use two nested For loops with one array autoindexed for each. This will lead to NxM iterations in total, where N and M are the number of elements of each list.

 

loopTerm.png


GCentral
0 Kudos
Message 5 of 7
(3,125 Views)

@VikashKumar23 wrote:

since the above binary are limited  I wanted to type values in a file and compare the binary data if it is present in the file.

 

I tried "Read Delimited Spreadsheet.vi". please see the attached image.

 

What it does is it compares only the first value of the row of a file. 

 

here I have two files. Binary.csv and Binary1.csv. 

 

Binary.csv has all the binary file. 

 

Binary1.csv file has only one binary value (1000010000100001). 


You are reading a CSV file which is a comma-separated value file usually encoded in plain text ASCII. It is NOT binary data. It is an ASCII representation of binary data.

 

In your VI, you are using the "Read Delimited Spreadsheet" and formatting the output as an I64 integer from one file, and a 64bit double from the other. Then converting all to U16 integers.

 

If this data is truly binary, what you are doing is wrong. The ASCII representation of the binary data (1000010000100001) will be literally interpreted as 1.000010000100001E+15 and doesn't fit in a 64bit double number without round off error, and definitely will not fit in a U16 integer. The binary data (1000010000100001) is 0x8421.

 

NOTE: You could always leave the data as ASCII and do the comparison with the strings.

 

 

Result.PNG

 

ASCII to Binary.png

0 Kudos
Message 6 of 7
(3,100 Views)
Solution
Accepted by topic author VikashKumar23

@VikashKumar23 wrote:

 

What it does is it compares only the first value of the row of a file. 

 

 

You are reshaping the 1D arrays to 1D arrays with 1 element each, so your FOR loop will only execute once (no matter what you wire to N). Also, if your FOR loop would execute 10 times, it would be so fast that all you see is the result of the last iteration.  You have not attached the csv files, so we cannot really tell how they are formatted, but as others have said, you are probably not reading them right.

 

All you probably need is get the single value from one file as a scalar, and the array of values from the other, compare them with "equal", followed by "OR array elements" from the boolean palette to get the result.

 

I strongly recommend to do a few more basic LabVIEW tutorials before continuing with all this.

0 Kudos
Message 7 of 7
(3,076 Views)