how i subtract a vector( 1*n-dim ) from columns of a matrix (n*n-dim) without uses for , end and orders likes these?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
i wish subtract a vector from columns of a matrix while my code is not great. example: a =
1 3
4 2
>> a-[1 2]= 0 1 3 0
0 Commenti
Risposta accettata
Stephen23
il 24 Apr 2015
Modificato: Stephen23
il 24 Apr 2015
>> A = [1, 3; 4, 2]
A =
1 3
4 2
>> B = [1, 2]
B =
1 2
>> bsxfun(@minus, A, B)
ans =
0 1
3 0
bsxfun expands any scalar dimensions to make the input variables the same size, then performs the specified operation. It is also much more efficient than using repmat.
Più risposte (1)
Joseph Cheng
il 24 Apr 2015
Look at the function repmat() to tile the vector to perform the matrix subtraction.
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!