Effacer les filtres
Effacer les filtres

Assigning matrix to cells

5 vues (au cours des 30 derniers jours)
Di Zhu
Di Zhu le 20 Mai 2016
Commenté : Di Zhu le 20 Mai 2016
Hello! I have preallocated the variable S with:S = cell(3,2); I want to assign the matrix [0 0 0] to each cell element, like this:
[0 0 0] [0 0 0]
[0 0 0] [0 0 0]
[0 0 0] [0 0 0]
I know that num2cell(zeros(3,2)) will give me
[0] [0]
[0] [0]
[0] [0]
Does anybody know if there is any way I can do this without using a for loop to assign [0 0 0] to each of the cell element? Thanks!

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 20 Mai 2016
Modifié(e) : Azzi Abdelmalek le 20 Mai 2016
cellfun(@(x) zeros(1,3),cell(3,2),'un',0)
Or
mat2cell(zeros(3,2*3),ones(1,3),3*ones(1,2))
  1 commentaire
Di Zhu
Di Zhu le 20 Mai 2016
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays 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