# HP Forums

Full Version: Access Matrix by row or column
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a command to select a specific column or row of a matrix?

Ie in Matlab this works:

A(3, : ) % Extract third row

The colon is used as a wildcard. I cant find a way to do this on the Prime except using SUB(), but that requires you to enter lists containing start and end indices of selected region so is not as convenient as wildcarding.

Actually, for a 2D Matrix, just using A(1) will select the 1st row ,but how to fo this for a column? I tried A(:,1) but this errors.
col(M,n) and row (M,n) will do the job.
(12-28-2017 11:38 AM)Arno K Wrote: [ -> ]col(M,n) and row (M,n) will do the job.

Thanks, I should have checked the catalog!
(12-28-2017 11:38 AM)Arno K Wrote: [ -> ]col(M,n) and row (M,n) will do the job.

yes. The Help mentions also the possibility to use an interval, but it doesn't give examples how to input the interval (both for row and cols)...

You can also use some code like this one to get a "minor" (giving the row and col to delete: i.e. using minor(2,3) in a 3x3 matrix deletes row 2 and col 3 and returns a matrix with (1,1), (1,2), (3,1), (3,2) ...
Code:

#cas
// Minor of a matrix
// r row, c col to delete
minor(m, r,c) :=
BEGIN
m:= delrows(m,r);
m:= delcols(m,c);
RETURN m;
END;
#end

Salvo

EDIT: how should input the interval in row() and col() in Home?
In CAS it's ok row(M2,2..3), a standard way to input an interval: why not implement it also in Home?
(12-28-2017 11:26 AM)Stevetuc Wrote: [ -> ].....
Actually, for a 2D Matrix, just using A(1) will select the 1st row ,but how to fo this for a column? I tried A(:,1) but this errors.

You can use negative values to select columns: A(-1) selects the 1st column
(12-28-2017 08:19 PM)JMB Wrote: [ -> ]
(12-28-2017 11:26 AM)Stevetuc Wrote: [ -> ].....
Actually, for a 2D Matrix, just using A(1) will select the 1st row ,but how to fo this for a column? I tried A(:,1) but this errors.

You can use negative values to select columns: A(-1) selects the 1st column

Thanks, thats concise syntax!
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :