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

1 次查看(过去 30 天)
I want to create a cell array of arbitrary size in which each cell contains a particular string, without a for loop.

采纳的回答

Matt Fig
Matt Fig 2012-11-8
编辑:Matt Fig 2012-11-8
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 个评论
Chris
Chris 2012-11-8
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by