LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete values from X and Y arrays

You are thinking about the problem in the "wrong way".

 

You have a set of "associated values":  X = [1, 2, 3, 4, 5] and Y = [10, 20, 30,40, 50].  Actually, the values of Y are immaterial, as you are only interested in their "association by Array position" with the values in X.

 

You have a "rule" for selecting valid versions of X, and you want to apply this rule "automatically" to the "associated" values of Y.

 

What's an easy way to express "association" of two identically-structured 1D Arrays?  Combine them into a 2D Array.  XY = [[1, 2, 3, 4, 5], [10, 20, 30, 40, 50]].  Now express the XY "association" more readily.  Note that you have a 2 x 5 Array, and LabVIEW "naturally" processes Arrays in Row order.  But you want to process it in Column order (which I will call T(X, Y) = [[1, 10], [2, 20], [3, 30], [4, 40], [5,50]]), in which case the first "row" processed would be [1,10].  Where's X?  It's the first element.  Is it In Range?  No, so you don't want to pass this value out of the While Loop that is "weeding out the bad elements".

 

Side question -- I assume you know about Indexing Tunnels, the tunnels that pop up on a For Loop when you bring an Array wire into the loop (and when you bring a wire out from the Loop).  Have you ever clicked on the output Indexing Tunnel and set the "Conditional?" flag?  Do you know what (wonderful) thing this does?  If not, learn more about Indexing Tunnels!  Needless to say, the Boolean output from In Range and Coerce belongs wired to the Indexing Tunnel.

 

So, if you've done things right, the output from this While Loop will be [[2, 20], [3, 30], [4,40]].  Not quite what you want, but what if you do the operation I called "T" (as in "transpose") two paragraphs ago?  You'll get [[2, 3, 4], [20, 30, 40]], a 2D Array whose first Element is the Valid X you wanted and whose second element is the Valid Y.  I assume you know the LabVIEW function (initials I.A.] that will get you these two 1D arrays out.

 

This is the solution to your post.

 

Bob Schor

Message 11 of 17
(558 Views)

Good morning , 

I will try to implement the solution you have given . 
I found a solution by myself yesterday by searching the index of the element in X and redeleting the same element in the same index in Y array.

Message 12 of 17
(535 Views)

@Mazespin wrote:

Good morning , 

I will try to implement the solution you have given . 
I found a solution by myself yesterday by searching the index of the element in X and redeleting the same element in the same index in Y array.


Your "solution" will certainly work in this (really simple) case.  But consider the following slightly more complicated example:

  • You have an Index column (with values 1, 2, 3, 4, ... 1000) and 5 data columns from 5 instruments with "data" (which you can simulate as "random values").
  • You want to keep only the data from trials whose index is an odd multiple of 3 (i.e. rows 3, 9, 15, ... 999).

To solve this (type of) problem, you need to treat the "index column" as "special" and operate on it so as to effect the entire row.  Ideally, this technique should work, regardless of the size(s) of the data, and with no assumptions about any column other than the Index Column.

 

Please test my suggestion.  Among other things, it will teach you some useful ideas and techniques for working with data arrays in LabVIEW.

 

Bob Schor

0 Kudos
Message 13 of 17
(523 Views)

Let's not wander too far into the woods. The OP want to select a range and that's it.

 

Note that XY graphs "understand" quite a few datatypes, so if you would use an array of points (clusters of x and y) using "build cluster array" or (even better!) into a 1D complex array, you can use "array subset" on the graph data much more easily.

 

For example here's how you could interactively select the desired range using two cursors:

 

altenbach_0-1687271759634.png

 

Message 14 of 17
(512 Views)

Excellent ! That's how I would do it. !

0 Kudos
Message 15 of 17
(509 Views)

Oh la la Mr. Altenbaaaaach. Welcome back!

By the way @Mazespin, I think this code by Mr. Altenbach is the solution to your problem. 

0 Kudos
Message 16 of 17
(469 Views)

"Correct, as usual, Christian" -- I paid more attention to the "Subject" of the Post, rather than reading carefully that the OP just wanted a range ...

 

Bob Schor

0 Kudos
Message 17 of 17
(460 Views)