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

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

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개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2012년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by