How to create a cell array with constant string entries without for loops.

1 vue (au cours des 30 derniers jours)
Chris
Chris le 8 Nov 2012
I want to create a cell array of arbitrary size in which each cell contains a particular string, without a for loop.

Réponse acceptée

Matt Fig
Matt Fig le 8 Nov 2012
Modifié(e) : Matt Fig le 8 Nov 2012
Here are a couple options. Note that the second option is probably preferable in some respects but can give you trouble if B is already defined.
str = 'mystring';
C = repmat({str},5,6)
B(1:5,1:10) = {str}
  1 commentaire
Chris
Chris le 8 Nov 2012
I had originally tried the last one, except without {} bracketing the string, which makes sense now that i see it. Both methods work great, and the latter does exactly what I need! Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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