Access Matrix by row or column
12-28-2017, 11:26 AM
Post: #1
 Stevetuc Member Posts: 101 Joined: Jan 2014
Access Matrix by row or column
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.
12-28-2017, 11:38 AM
Post: #2
 Arno K Senior Member Posts: 430 Joined: Mar 2015
RE: Access Matrix by row or column
col(M,n) and row (M,n) will do the job.
12-28-2017, 11:48 AM
Post: #3
 Stevetuc Member Posts: 101 Joined: Jan 2014
RE: Access Matrix by row or column
(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:49 AM (This post was last modified: 12-28-2017 03:36 PM by salvomic.)
Post: #4
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Access Matrix by row or column
(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?

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-28-2017, 08:19 PM
Post: #5
 JMB Member Posts: 83 Joined: Jan 2016
RE: Access Matrix by row or column
(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-29-2017, 02:45 PM
Post: #6
 Stevetuc Member Posts: 101 Joined: Jan 2014
RE: Access Matrix by row or 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!
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)