简体   繁体   中英

Subtracting a single column matrix from a 5x5 matrix in matlab

so say i have a column matrix A that is 5x1 and a 5x5 matrix B. i want to subract A from each column in B.

[b1,1 - a1   b1,2 - a1    b1,3 - a1     b1,4 - a1    b1,5 - a1]
[b2,1 - a2 ...................................................]
[b3,1 - a3 ............ 
[b4,1 - a4 ............
[b5,1 - a5 ..... etc

yes, that is a very terrible description, but i hope it gets the point across. I know that in octave it will automatically do this if you say B - A. But in matlab it wont.

Here are a few options:

Just make A into a 5x5 matrix by repeating the columns:

B-repmat(A,1,size(B,2))

And the obligatory bsxfun method:

bsxfun(@minus,B,A)

创建具有5个副本的矩阵a作为它的列,然后从减去它B

C = B - repmat(a, 1, 5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM