How do I add column vector to a matrix ? Documentation examples does not work.
30 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
norcalpedaler
le 30 Nov 2016
Commenté : Guillaume
le 30 Nov 2016
I copied this example directly from the documentation and it returns error "Matrix dimensions must agree". What is going on? A = [1 2 3; 4 5 6] A =
1 2 3
4 5 6
b = [10; 100] b =
10
100
A + b ans =
11 12 13
104 105 106
0 commentaires
Réponse acceptée
Steven Lord
le 30 Nov 2016
Implicit expansion was added as a feature in MATLAB in release R2016b. You're using an older release, one in which you would have to use the bsxfun function to explicitly ask for the same expansion behavior for vectors and matrices.
1 commentaire
Guillaume
le 30 Nov 2016
in other words, in older versions:
bsxfun(@plus, A, b)
Plus de réponses (1)
dbmn
le 30 Nov 2016
hi,
this works like this
A=[A, b]
2 commentaires
dbmn
le 30 Nov 2016
Sorry, i understood that the wrong way.
I might still not fully understand it. Can you give an example of how the output should look like?
Something like this?
sum(A+b)
ans =
115 117 119
Or this?
cumsum(A+b)
ans =
11 12 13
115 117 119
Or this?
cumsum(sum(A+b))
ans =
115 232 351
Voir également
Catégories
En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!