Ask Your Question
0

How to copy specific number of columns from a matrix to another matrix?

asked 2016-04-28 08:23:43 -0600

I know the way to copy specific rows from one matrix to another but how can I copy only a specific number of columns from one matrix to another? For example, if we have 10x10 matrix A (10 rows and 10 columns)and I want to copy only the columns ranging from 1 to 5 to another matrix B. Is it possible?

Note: I can't delete the columns from matrix A first.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-04-29 05:40:52 -0600

updated 2016-06-10 02:52:24 -0600

This can be done by defining first the size of matrix B as the number of columns that you want after deletion and same number of rows as in matrix A.

The command is A.col(a).copyTo(B.col(b)) and you must run a loop over command according to your copying pattern between two matrices.

edit flag offensive delete link more
1

answered 2016-04-28 08:42:40 -0600

kbarni gravatar image
Mat B=Mat(A,Rect(0,1,A.rows,5));
Mat C;
B.copyTo(C);

B will be a part of matrix A (if you change A, B will change, too). C is a copy of B (so they are independent).

edit flag offensive delete link more

Comments

i think Mat B=Mat(A,Rect(0,0,A.rows,5));

sturkmen gravatar imagesturkmen ( 2016-04-28 09:04:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-28 08:23:43 -0600

Seen: 1,716 times

Last updated: Jun 10 '16