From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

add the elements of a single row/column of a matrix

Solved!
Go to solution

Hello everyone,

what's the easiest way to add all the elements of a single row or column of a matrix given the matrix and the number of that row/column on LabVIEW ? The output should be a number for each row or column.

0 Kudos
Message 1 of 10
(4,770 Views)

I'm assuming you are very new to LabVIEW, otherwise you would know about For loops, indexing, and the Array functions.  In many programming languages, a "matrix" is just a multi-dimension array, but in LabVIEW, it is a different representation of a multi-dimension array.

 

If you are really working with a LabVIEW Matrix, the easiest way might be to convert the matrix to a 2D array and use the various Array functions to do the work.  Note that once you have the row or column isolated as a 1D array, there is a function on the Numeric palette that will add the array elements for you (so you don't need the For loop to do that).

 

P.S. -- I underlined "might be", above, because I've never actually used LabVIEW's Matrix functions, but have stuck with 2 (or 3, or 4) dimension arrays.

 

Bob Schor

0 Kudos
Message 2 of 10
(4,756 Views)

Do you  have an arry or a matrix? In LabVIEW they are different datatypes.  The matrix datatype is typically used only when the specialized linear algebra functions are needed.

 

To do what you ask with the much more commonly used array datatype, use Index Array (array palette) followed by Add Array Elements (Numeirc palette).

 

Lynn

0 Kudos
Message 3 of 10
(4,751 Views)

Thank you both for the quick response and the helpful tips.
Actually my problem was separating each row or column, to be able to use the "add array elements" function. But I realized it can be done automatically once I wire the matrix array through an auto-indexing tunnel of a loop. Then i could simply transpose the matrix to be able to work with rows only or column only.

Arij

0 Kudos
Message 4 of 10
(4,724 Views)
Solution
Accepted by topic author ArijJendoubi

Arij,

 

You still have not indicated whether you are using an array or a matrix.

 

The Transpose should be outside the loop.

 

This will give you the sums of all rows and all columns.

 

These are basic LabVIEW constructs and functions. If you do not understand the concepts, please look at the on-line tutorials.

 

Lynn

 

Array sums.png

Message 5 of 10
(4,708 Views)

I'm using a matrix, and I did place the transpose function outside the loop, and got pretty much the same block diagram you have there.

Thank you though

0 Kudos
Message 6 of 10
(4,699 Views)

Yes, for this kind of code it is irrelevant if you have a 2D array or a matrix. same difference.

 

Is your problem solved?

0 Kudos
Message 7 of 10
(4,690 Views)

yes it is.

0 Kudos
Message 8 of 10
(4,677 Views)

It is helpful, as the Original Poster, for you to mark the response that you consider "The Solution" as The Solution (in case later visitors with similar questions find your post).

 

BS

0 Kudos
Message 9 of 10
(4,662 Views)

Oh, I didn't know this feature mattered. As you can see, I'm new to labview, AND to this community. But i like it, and i'll do as you said.

0 Kudos
Message 10 of 10
(4,632 Views)