08-18-2010 09:14 AM
Hi
I would like to insert a sub-array (row) into a 2D array at the correct index. The position ie index value is depended on the value of the first column of the 2d array.
As an examlple my 2d array would look like this
230 50 215 255
300 60 270 330
360 20 350 370
And I would like to insert another row (sub-array) with the following values
320 40 300 340
This new row should be placed between the second and third row (it is depending on the first column only).
I have tried the Threshold 1D array function by taking a 1Dsub-array from my 2d array (first column) and then using the first value of the new row (320) as a threshold. It sort of work but it does not work when I start the array (ie there is only 1 row) and it seems to not work correctly on other occasions (as explained in the Labview help).
Hope the explanation is clear enough for any suggestions. Thank in advance for the help!
Solved! Go to Solution.
08-18-2010 09:29 AM - edited 08-18-2010 09:30 AM
JTRI, please look at the attached example.
You will need to compare the first column of your subarray to the first column's element in each row.
* Note: this will only work if your array is sorted as you have shown in your example.
Is this always going to be the case?
Or is that what you wanted this function for in the first place?
08-18-2010 09:45 AM
08-18-2010 10:00 AM
Hi
Thanks for the quick reply! I tried to open your VI but I am working with version 8.2 so it did not open.
Can you please repost with the VI saved for a previous version (8.2)or post it as an image?
Your solution sounds great and seems along the lines of what I am trying to do.
The idea is that I start with a new array and add these rows in the right sequence every time the user defines the values (including the first column) I would like to sort them 'actively' / 'in real time' rather then gather all the data and then sort it. If the indexing works well from the start then the 2D array should always be in the right order (that is the exact idea).
I have tried use the Threshold function but it somehow falls over because I am starting with an empty array ie it can not work when the 2D array has only one value in it.
Many thanks
Jack
08-18-2010 10:02 AM
Sure here you go.
08-18-2010 10:12 AM
@JTRI wrote:
The idea is that I start with a new array and add these rows in the right sequence every time the user defines the values Jack
Ahh, then try this.
This will work with an empty array too.
What you will want to do with this function is make it a subVI.
Make the 'array' and 'subarray' inputs on the connector, then 'new array' an output.
You can then put this subVI in a loop with a shift register and it will help add all the new rows in sorted order as they are added.
Is that what you were shooting for?
08-18-2010 10:18 AM
08-18-2010 10:23 AM
Hi again
Thanks Cory K that seems to do the trick. I will have a play with it to make sure it does not fall over but so far so good!
Excellent!
Regards
Jack
12-27-2010 08:25 AM
I seem to have a similar problem, but my data is in a different format i.e.
Col1 Col2 Col3 Col4
"Testing Testing 0 0
Testing Testing 4 1
Testing Testing 7 0
Testing Testing 12 2
Testing Testing 14 1"
From above 2D array, Column 1 & Column 2 represent Data, but column 3 and column 4 represent Row and Column respectively.
Basically numbers on col 3 & 4 indicate where col 1 & 2 should be placed in a 2D arra, and for the missing rows where there is no data, it should be padded with Empty arrays.
This is more of an "Idea" problem that I'm having rather than programming. Any help is appriciated.
Thanks
Kas
12-27-2010 09:16 AM