Search 2d array and extract index
Need a little help with a simple problem.
I'm working on an image correlation project where the end result is an array MxN
all of the values of my array vary between -1 and 1 and I need to extract the indexes (row and colum) of this 2D that are greater than or equal to 0.9.
The row corresponds to a specific point of an intensity graph and the colum to a point on another image.
Any guesses as to how to extract my indexes?
Thanks in advanced
Bruno Noronha
Certified LabVIEW Associate Developer
Using LabVIEW 8.6
rpage wrote:
Maybe next time your comments can be more constructive instead of bashing other peoples' example code.
How unprofessional for a professional site.
I agree that it is quite unprofessional to throw out example code that is highly flawed and showcases bad coding habits. The new users here seeking advice deserve better. I am serious! I can guarantee you that the users will run the code more than once, so having the uninitialized shift register can lead to serious confusion.
Thus my constructive criticism, mentioning some of the flaws. There was no bashing intended, and if you feel I did, I am sorry. Maybe I will use a few more smileys next time.
Here's how it should have looked like. I would guess it would have taken faster to code because there is less code to do the same thing. (no index array, no need to wire the N's of the second loop, no flat sequence, fits on a laptop screen, ...)
I am by no means perfect, for example I misspelled one of the indicator terminals
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Search2DArray.png 8 KB
Similar Messages
-
Hello,
Is there a java method that would sort an array of doubles and also return the original indexes of the array elements.
There is Array.sort(myArray), however the method does not give the original indexes.
Writing a code on sorting and getting the indexes does not sound attractive while java has effective methods to sort.
Thanks!devboris wrote:
Can you ellaborate more on the code? I have not used a Comparator before.i think he/she means something like this, you can use the Comparator to sort the array post your attempt at sorting the array before asking for more help
public class TestArray {
ArrayElement[] myArray = new ArrayElement[10];
public void populateArray(){
for(int i = 9;i>=0;i--){
myArray[i] = new ArrayElement(i,9-i);
public void sortArray(){
//leave this to you
public void printArray(){
for(int i = 0;i<myArray.length;i++){
System.out.println("Orig pos is "+myArray.getIndex()+" and value is "+myArray[i].getValue());
public static void main(String[] args){
TestArray test = new TestArray();
test.populateArray();
test.sortArray();
test.printArray();
}//end of class
class ArrayElement {
public int index;
public double value;
public ArrayElement(int i, double v){
this.index = i;
this.value = v;
public int getIndex(){
return this.index;
public double getValue(){
return this.value;
}//end of classHope this helps
Calypso -
How do i convert a picture back to a image array and extract the coulor table.
Been trying to do so for the past 2 weeks and the folks at NI India also are unable to support me. please help. I am on labview 6.1
AnkurI suppose that you are talking about a LV picture.
My opinion is that LV 6 was an absolute pity for picture management. LV 7 is only a pity.
Your problem could be solved in a breath using a few of the IMAQ vision tools. Unfortunately, NI has decided to keep separated its image management tools from its graphic development environment. I think that this situation should be discussed...
With LV 6, there is probably a solution that use the Flatten to String function, convert the string to a 1D-array of bytes, remove the 32 bytes or so the Flatten function has added before the actual picture bytes, then reshape the array according to the initial picture size. I have done that in the past for a 8byte picture. Not sure if it is as simple for a colored picture. Not sure either if I'll have some time to spare on the problem today.
Hope you will find here some more constructive help !
CC
Chilly Charly (aka CC)
E-List Master - Kudos glutton - Press the yellow button on the left... -
Is there a way to search an array?
Post Author: Andrew Reedick
CA Forum: Formula
CR has the 'x in [y]' operator which will tell you if x in is in array y. However that returns a boolean.
Is there anything that will search an array and return the index if the item is found? Or do I have to write my own formula to do so? (This is using CR syntax.)
On a side note, does CR syntax support multi-dimension arrays?Post Author: Andrew Reedick
CA Forum: Formula
CR has the 'x in [y]' operator which will tell you if x in is in array y. However that returns a boolean.
Is there anything that will search an array and return the index if the item is found? Or do I have to write my own formula to do so? (This is using CR syntax.)
On a side note, does CR syntax support multi-dimension arrays? -
I'm a MB Pro beginner (after 25 years with PC). I have an Iomega ext HD, but how do get it indexed?, and it doesn't come up with any results I'm trying searches in Finder, and it says "searching Iomega drive" - but I don't think it's indexing. How do I force it to index?
Well I'm leaning the other way. I think my present MBP will be the last Apple product I buy.
With the way Apple is going, all New Mac computers are sealed unit that don't allow the user to upgrade them in any way. They are getting more expensive initially. They are impossible to fix, even by Apple. All the parts are either soldered to the Logic Board or glued inside the case parts. The add on warranty only covers manufacturing defects and is expensive. And to fix one out of waranty is close to if not more then a new system.
The only thing different in a Mac, and most other products Apple sells, is the operating system and the cases they come in. As for the OS both have their glitches and at this time there are no viruses that infect OS X. There is more software available for Windows. More choices as to what hardware you can use or upgrade to at a later date.
Mac computers are becoming large iPads or iPhones with built in keyboards.
jeremy_from_rome wrote:
And as for the question: PC or Mac, the consensus that I hear from colleagues and friends is just as you state it: stay with Mac, be patient, work at it, and you’ll never look back! Thanks again -
Search data in a 2d array and generate a signal when found
Hi, i am looking for an interactive way to search data from an array containing a 2d array found in a cluster. The data is in the 2d array. I have attached the vi containing the array. I want an interactive method to look up for the codes in the 2d array(found in the 1st row) and when found generate a signal to tell it has been found. The signal varies depending in which category was data code found (whether engineering, law or others). Btw the data i am looking for are in fact input using a barcode reader. Should i use a search 1d array function? or is there another method?
Solved!
Go to Solution.
Attachments:
Untitled 1.vi 6 KBJust to make sure we are totally clear here. We are trying to find the cluster which contains a certain data point in its first row of the 2D array?
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Search for element.png 14 KB -
Search given string array and replace with another string array using Regex
Hi All,
I want to search the given string array and replace with another string array using regex in java
for example,
String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
String fromValue[] = {"you", "search", "for", "any"}
String toValue[] = {"me", "dont search", "never", "trip"}
so the string "you" needs to be converted to "me" i.e you --> me. Similarly
you --> me
search --> don't search
for --> never
any --> trip
I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
One Single regular expression which matches the pattern and solve the issue.
the output should be as:
If me wish to don't search never trip etc...,
Please help me to resolve this.
Thanks In Advance,
KathirAs stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
import java.util.regex.*;
public class Test
static final List<String> oldWords =
Arrays.asList("you", "search", "for", "any");
static final List<String> newWords =
Arrays.asList("me", "dont search", "never", "trip");
public static void main(String[] args) throws Exception
String str = "If you wish to search for any of these characters, "
+ "they must be preceded by the character to be interpreted";
System.out.println(doReplace(str));
public static String doReplace(String str)
Pattern p = Pattern.compile("\\b\\w+\\b");
Matcher m = p.matcher(str);
StringBuffer sb = new StringBuffer();
while (m.find())
int pos = oldWords.indexOf(m.group());
if (pos > -1)
m.appendReplacement(sb, "");
sb.append(newWords.get(pos));
m.appendTail(sb);
return sb.toString();
} This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays). -
How to ask for an array and how to save the values
I'm supposed to be learning the differences between a linear search and a binary search, and the assignment is to have a user input an array and search through the array for a given number using both searches. My problem is that I know how to ask them how long they want their array to be, but I don't know how to call the getArray() method to actually ask for the contents of the array.
My code is as follows:
import java.util.Scanner;
import java.util.ArrayList;
public class Main
private static Scanner input = new Scanner(System.in);
public static void main (String args[])
//creates ArrayList
int List[];
System.out.println("How long would you like the array to be?");
int arrayLength = input.nextInt();
//Initializes array list
List = new int [arrayLength];
System.out.println("Please enter the first value of the array");
public static void getArray(int List[], int arrayLength)
for(int i=0; i < arrayLength; i++) {
System.out.println("Enter the next value for array");
List[i] = input.nextInt();
public static void printArray(int List[])
for(int i=0; i < List.length; i++)
System.out.print(List[i] + " ");
public class search
public static int binarySearch(int anArray[], int first, int last, int value)
int index;
if(first > last) {
index = -1;
else {
int mid = (first + last)/2;
if(value == anArray[mid]) {
index = mid; //value found at anArray[mid]
else if(value < anArray[mid]) {
//point X
index = binarySearch(anArray, first, mid-1, value);
else {
//point Y
index = binarySearch(anArray, mid+1, last, value);
} //end if
} //end if
return index;
//Iterative linear search
public int linearSearch(int a[], int valueToFind)
//valueToFind is the number that will be found
//The function returns the position of the value if found
//The function returns -1 if valueToFind was not found
for (int i=0; i<a.length; i++) {
if (valueToFind == a) {
return i;
return -1;I made the changes. Two more questions.
1.) Just for curiosity, how would I have referenced those methods (called them)?
2.) How do I call the searches?
import java.util.Scanner;
import java.util.ArrayList;
public class Main
private static Scanner input = new Scanner(System.in);
public static void main (String args[])
//creates ArrayList
int List[];
System.out.println("How many values would you like the array to have?");
int arrayLength = input.nextInt();
//Initializes array list
List = new int [arrayLength];
//Collects the array information
for(int i=0; i < arrayLength; i++) {
System.out.println("Enter a value for array");
List[i] = input.nextInt();
//Prints the array
System.out.print("Array: ");
for(int i=0; i < List.length; i++)
System.out.print(List[i] + " ");
//Asks for the value to be searched for
System.out.println("What value would you like to search for?");
int temp = input.nextInt();
System.out.println(search.binarySearch()); //not working
} -
How to create Search help exit, and then assign it to a collective search
hi gurus,
i have an intersting question for you, well my scenario is like i have to create a search help exit using some function module cause i didt found table for my search help but i can find the value through FM, i know we can create a search help exit and then assign it to collective search help,
my problem is what are the parameters i need to pass to this search help exit FM, and in the function module i want to use the value entered on the f4 selection screen to extract data through FM. i need to give a solution asap.
any reply will be highly appreciated
n rewards points for sure.
thanks mandyHi mandy,
Have a look at this code,
FUNCTION SHLP_SHOW_LIST.
""Local interface:
*" IMPORTING
*" VALUE(PLANT) TYPE WERKS_D OPTIONAL
*" VALUE(DISPLAY_ONLY) TYPE FLAG OPTIONAL
*" EXPORTING
*" REFERENCE(ITEM_SELECTED) TYPE CHAR20
*" EXCEPTIONS
*" POPUP_CANCELED
TYPE-POOLS SHLP .
CONSTANTS:
co_shlpname TYPE shlpname VALUE 'SHLP_CONTAINER',
co_shlpfield_itemalias TYPE ddshlpsfld VALUE 'CONTAINER'.
DATA: l_shlp TYPE shlp_descr_t,
l_subrc TYPE sysubrc,
l_return_tab TYPE STANDARD TABLE OF ddshretval,
l_return_wa TYPE ddshretval,
l_interface_wa TYPE ddshiface.
Get details for search help
CLEAR l_shlp.
l_shlp-shlpname = co_shlpname.
l_shlp-shlptype = 'SH'.
CALL FUNCTION 'DD_SHLP_GET_HELPMETHOD'
CHANGING
shlp = l_shlp.
Assign virtual screen field
READ TABLE l_shlp-interface INTO l_interface_wa
WITH KEY shlpfield = co_shlpfield_itemalias.
l_interface_wa-value = space.
l_interface_wa-valtabname = 'X2'. "virtuel screen field
l_interface_wa-valfield = 'Y2'. "virtuel screen field
MODIFY l_shlp-interface FROM l_interface_wa INDEX sy-tabix.
Call F4 popup
CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
EXPORTING
shlp = l_shlp
disponly = display_only
IMPORTING
rc = l_subrc
TABLES
return_values = l_return_tab
EXCEPTIONS
OTHERS = 0.
IF sy-subrc = 0 AND l_subrc = 0.
Value selected
READ TABLE l_return_tab INDEX 1 INTO l_return_wa.
item_selected = l_return_wa-fieldval.
ELSE.
Popup canceled / no value selected
RAISE popup_canceled.
ENDIF.
ENDFUNCTION.
make sure to call these FMs and populate accordingly...
Thanks
Madhu -
How to save data in a 4D array and make partial plots in real time?
Hi, this is a little complex, so bear with me...
I have a test system that tests a number of parts at the same time. The
experiment I do consists of measuring a number of properties of the
parts at various temperatures and voltages. I want to save all the
measured data in a 4-dimensional array. The indices represent,
respectively, temperature, voltage, part, property.
The way the experiment is done, I first do a loop in temperature, then
in voltage, then switch the part. At this point, I measure all the
properties for that condition and part and want to add them as a 1D
array to the 4D array.
At the same time, I want to make a multiple plot (on an XY graph) of
one selected property and part (using two pull-down selectors near the
XY graph) vs. voltage. (The reason I need to use an XY graph and not a
waveform graph, which would be easier, is that I do not have
equidistant steps in voltage, although all the voltage values I step
through are the same for all cases). The multiple plots are the data
sets at different temperatures. I would like to draw connection lines
between the points as a guide to the eye.
I also want the plot to be updated in the innermost for loop in real
time as the data are measured. I have a VI working using nested loops
as described above and passing the 4D array through shift registers,
starting with an array of the right dimensions initialized by zeroes. I
know in advance how many times all the loops have to be executed, and I
use the ReplaceArraySubset function to add the measured properties each
time. I then use IndexArray with the part and property index terminals
wired to extract the 2D array containing the data I want to plot. After
some transformation to combine these data with an array of the voltage
values in the form required to pass to the XYGraph control, I get my
plot.
The problem is: During program execution, when only partial data is
available, all the zero elements in the array do not allow the graph to
autoscale properly, and the lines between the points make little sense
when they jump to zero.
Here is how I think the problem could be solved:
1. Start with an empty array and have the array grow gradually as the
elements are measured. I tried to implement this using Insert Into
Array. Unfortunately, this VI is not as flexible as the Replace Array
Subset, and does not allow me to add a 1D array to a 4D array. One
other option would be to use the Build Array, but I could not figure
out if this is usable in this case.
2. The second option would be to extract only the already measured data
points from the 4D array and pass them to the graph
3. Keep track of the min. and max. values (only when they are different
from zero) and manually reset the graph Y axis scale each time.
Option 3 is doable, but more work for me.....
Option 2: I first tried to use Array Subset, but this always returns an
array of the same dimensionality of the input array. It seems to be
very difficult, but maybe not impossible, to make this work by using
Index Array first followed by Array Subset. Option 3 seems easier.
Ideally, I would like option 1, but I cannot figure out how to achieve
this.
Your help is appreciated, thanks in advance!
germ Remove "nospam" to replyIn article <[email protected]>,
chutla wrote:
> Greetings!
>
> You can use any of the 3D display vi's to show your "main" 3d
> data, and then use color to represent your fourth dimension. This can
> be accessed via the property node. You will have to set thresholds
> for each color you use, which is quite simple using the comparison
> functions. As far as the data is concerned, the fourth dimension will
> be just another vector (column) in your data file.
chutla, thanks for your post, but I don't want a 3D display of the
data....
> Also, check out
> the BUFFER examples for how to separate out "running" data in real
> time.
Not clear to me what you mean, but will c
heck the BUFFER examples.
> As far as autoscaling is concerned, you might have to disable
> it, or alternatively, you could force a couple of "dummy" points into
> your data which represent the absolute min/max you should encounter.
> Autoscaling should generally be regarded as a default mode, just to
> get things rolling, it should not be relied on too heavily for serious
> data acquisition. It's better to use well-conditioned data, or some
> other means, such as a logarithmic scale, to allow access to all your
> possible data points.
I love autoscaling, that's the way it should be.
germ Remove "nospam" to reply -
How do you save characters in an array and then output the characters as a string one by one.
I want to know how to save a number of different characters to an array. then after open this array and read these values one by one as a string.
Input to your loop has indexing enabled. What happens is that on the first iteration, the indicator displays the first string in the array, then in the next iteration, the indicator displays the second string in the array, the first one is overwritten. This happens so fast that all you see is the second one. Look at attached vi in LV6.1 to see how to concatenate both into one indicator. You really need to study Labview to learn the functions. Go to NI's website and search for Labview tutorials.
- tbob
Inventor of the WORM Global
Attachments:
ConcatString.vi 28 KB -
Searching 1D array for data present in lookup 1D array.
Hi!,
I have a sorted 1D array of strings(say initial array) and I have
three lookup array of string(say array A, array B and array C). I want
to search the initial array with array A, array B and array C and then
create a new array Final which will contain the elements of array A,
if any, its start index and its last index and then element sof
arrayB, if any found, its start index and its end index and then
element of array C its start index and its end index.
The start index and end index are stored in different indicatrs for
all the three found.
How do I search elements of 1D array with another 1D array?
TIA,
RKThere are probably several ways to do it. One way to do it you would create a For Loop with the initial array run into it with auto-indexing turned off. You would then run array A into it with auto-indexing turned on. Inside of the loop, you would use a Search Array to find the index (if any) of the element in the initial array that matched the auto-indexed element of Array A. You will want to either build an array of only the indexes >=0 (trapping the "not found" -1) or you can autoindex the results and have you later code deal with them.
You will need three of these loops, one for each searching array. Or better, you could push it into a subVI and call it three times.
I hope that this helps!
Bob Young
Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
DISTek Integration, Inc. - NI Alliance Member
mailto:[email protected] -
Parse a WebPage and Extract Data
Hi, i've figured out how to get an html source using a java class posted earlier on this forum. I wanted to find out what is the best and easiest way to extract information from it. I have been searching the web and read a lot about using XML. Is that the best way to do it, or is there something else i can use ? Thanks !
I would suggest building your own statements.
I am not sure which web site you are trying to get data from. However the previous response was correct. HTML has to be well formed which often it is not. Even the most professional web sites have bad HTML code.
I am not sure if you are looking to extract data from one web site or various (please let me know).
here is an example of how you 'might' wish to do it:
HTML CODE:
<td nowrap><font face="Arial" size="3"><b>Description</b></font></td>
<td width="100%"></td>
<td nowrap width="100%" align="right">WonderfulDescription</font>
</td>
CODE:
String description //Field to store the description
int startIndex //Index of where description starts
int endIndex //Index of where description ends
while (readLine...) //That while loop from the previous code I gave
if (readLine.indexOf("Description" != -1)
HTMLpage.readLine(); // Read line 1 - hence: <td width="100%"></td>
readLine = HTMLpage.readLine();
startIndex = readLine.indexOf("align=\"right\">") + 14;
endIndex = readLine.indexOf("</font>");
description = readLine.subString(startIndex, endIndex);
}This is ideal if there is specific information in the page that you wish to obtain. But coding it takes time and you have to study the web page layout carefully. I suggest putting a System.out.println(readLine) statement in the while loop. The copying and pasting the output into FrontPage and looking at it. Dont copy and paste the source from ViewSource in Internet Explorer as it will not show you dynamic data.
Let me know how you get on. As always, get back to me if you have any questions.
Kind regards
Angus -
How to search for array in another array ?
i want to search for array in another and when i got this array i want to take the next 5 bits EX: array1 [ 4 8 7] , array2 [ 9 1 4 8 7 6 3 2 ] , output array [ 6 3 2 9 1]
ThanksI know we should be encouraging others to help them selves, but I had a solution that I think is what the user wants. Attached is a VI that searches for a subarray in an array, and will return the index it is found at. It will also return the input array, filtered if a match is found. This VI just handles the double data type.
Most of the code comes from an old post by Altenbach that I can't seem to find at the moment, but I saved a copy a while ago. Props to him for posting it.
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
Attachments:
Filter Subarray - DBL.vi 18 KB -
I need to search for a 2D array, and report the row index. I have serached the array and mathematics functions, but none can handle this extrememly simple task, that is easily done in all other software,(MATLAB, VB, Excel etc).
I hope I am wrong, and there is a simple VI to handle this task, because I introduced LabVIEW to my colleagues, and I feel embarrased, when they asked me this question, and I can not find a simple VI, but have to start designing a for or while loop for a simple task.DFGray wrote:
It may be faster to reshape the array to a 1D array, do the search (once), then reshape back to 2D (presuming you are using again. You will need to convert from position in the 1D array to position in the 2D array, but that is a simple operation.
Here's an old example.
(To find only the first match, delete the two loop structures. )
(If there is only one match, you could do a comparison between the array (of any dimension!) and the element to be found, followed by "boolean to 0,1), followed by "array min/max". The index output of the array max is the desired value. )
DFGray wrote:
Please add this functionality as a suggestion in the LabVIEW Idea Exchange. I will vote for it!
The functionality we need is is a simple polymorphic VI ("Search array" would replace the current "search 1D array") that accepts arrays of any dimensionality and returns the index as an array, one element for each dimension. The start index would accept such an array too. (There might be some problems incrementing to the next element when searching for multiple occurrences, so we might need some helper tools).
The function would search the elements in the order of the flattened array.
LabVIEW Champion . Do more with less code and in less time .
Maybe you are looking for
-
PDF custom landscape page size - - content squashed portrait
I'm trying to create a PDF for an MS PowerPoint file with a very large page size, 46" x 36" (landscape). I'm using Acrobat 7.0 on Windows XP. In keeping with guidelines at www.adobeforums.com/webx/.3bbad46c/0 I selected the printer properties and cre
-
I have a Mac running OS X 10.6.8 and have installed all updates and have disabled Java Applets. Do I need to install antivirus software and, if so, do you have a recommendation on what works best.
-
Adding Custom fields in ECC Business partner BP - (BUT000) using BDT or EEW
Hello BDT / EWWB Gurus, We have a requirement to add custom fields to ECC Business partner, which interns create custom fields in But000 table. I would be great if anyone could let us know how to add Custom fields using BDT or EEWB. Please also elabo
-
Temporary tablespace and tempfile
Hi, On one of our database, we have a temporary tablespace which is locally managed. This tablespace has 3 tempfiles. One query, which generate large sort, cause an Oracle error ORA-01652. But, when we see the date of tempfiles, it seems that there i
-
Make this query more elegant?
can anybody tell me how to make this subquery more elegant? select 1 lfdidx from dual union select 2 lfdidx from dual union select 49 lfdidx from dual union select 50 lfdidx from dual Thanks in advance