Effacer les filtres
Effacer les filtres

Vectorisation of 2 2d matrix

1 vue (au cours des 30 derniers jours)
Li zifan
Li zifan le 27 Août 2018
Modifié(e) : Stephen23 le 27 Août 2018
Hi, I want to answer of 2 arrays without using loops,
A=rand(100,100)
B=rand(8,1)
The out put C is going to be a 100*100*8 array, each layer is the difference between A and corresponding B row.
e.g. The second layer of C is gonna be A(:,:)-B(2,:).
Is there a way to manage this with out for loop?
Thanks

Réponse acceptée

Stephen23
Stephen23 le 27 Août 2018
Modifié(e) : Stephen23 le 27 Août 2018
For MATLAB versions R2016b+:
C = A - reshape(B,1,1,[])
For earlier versions:
C = bsxfun(@minus,A,reshape(B,1,1,[]))

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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!

Translated by