cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Compute Row Sums of a Matrix

Problem

You have a matrix stored in JSL, and you would like to create a column vector that contains the sums of each row of values in the matrix.

Solution

Use a combination of the V Sum() function and matrix transposes:


M = [1 2 3, 4 5 6, 7 8 9];
V = V Sum( M` )`;
Show( V );

The above script results in the following output in the Log window:

Show( V );
/*:

V = [6, 15, 24];

 

Discussion

 

See Also

 

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.