LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I subract 1d of a 2d array?

I have 2 sets of 2d array of numbers and I would like to subract only the second dimension of numbers and leave the data alone in the first dimension. Any Idea how to go about this? here is an example of what my arrays look like
 
1.5    
0 Kudos
Message 1 of 11
(4,818 Views)

my 2 sets of arrays look like this:

Set 1

1.5  2.5  3.5

10   20   30

 

Set 2

1.5  2.5  3.5

  1     2    3

 

What I want to do is subract the second dimension of set 2 from set 1 to get the following resultant 2d array

Resultant array

1.5  2.5  3.5

  9   18   27

Thanks,

Phil

0 Kudos
Message 2 of 11
(4,803 Views)
Hi Phil T,

Attached below, I have included a VI that I think achieves what you describe. When you run the program, the desired calculations you are seeking are carried out and placed into the "Resultant array".

Be aware that I am still relatively new to LabVIEW and that there may be a simpler way to achieve your desired result with less coding.

Message Edited by Anthony_Wong on 06-27-2006 10:25 AM

Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 3 of 11
(4,782 Views)

Another option. You can work with 1D arrays then build it up again

David

Message Edited by David Crawford on 06-27-2006 04:26 PM

Message 4 of 11
(4,768 Views)

Message Edited by SarahB on 06-27-2006 10:28 AM

Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 5 of 11
(4,764 Views)
Here's a slightly less bulky method.  The principle is exactly the same as Anthony's, however it uses the fact that the basic functions (in this case subtract) are so flexible.

Edit: Oops, while I was creating that VI there were a few others posted.

Message Edited by Novatron on 06-27-2006 11:32 AM

0 Kudos
Message 6 of 11
(4,755 Views)
I suspected that the subtract function was flexible and edited my post to reflect that (i.e. rather than extracting the elements individually, just simply subtract the two subarrays).

Thanks for the tip though Novatron.
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 7 of 11
(4,749 Views)


@Anthony_Wong wrote:
I suspected that the subtract function was flexible and edited my post to reflect that (i.e. rather than extracting the elements individually, just simply subtract the two subarrays).

Thanks for the tip though Novatron.



This flexibility is called "polymorphism".  I think most if not all arithmetic (numeric functions) operators are polymorphic.  It's a handy thing to know about.

If you encounter a non-polymorphic function, and you want to apply it to a whole array you have to index into the datatype, somehow (usually using a for or while loop with indexing enabled, and iterate the whole length of the array),

0 Kudos
Message 8 of 11
(4,731 Views)
It is often easier to use autoindexing. Here's an alternative approach that does not use any explicit index array functions. 😄
 
 
 

Message Edited by altenbach on 06-27-2006 09:27 AM

Download All
Message 9 of 11
(4,717 Views)
Thanks to all who helped
0 Kudos
Message 10 of 11
(4,691 Views)