Overwrite empty cell array with strings
4 次查看(过去 30 天)
显示 更早的评论
I have an empty cell array, I want to add a row of strings to this matrix.
The empty matrix is 12x100. The row of strings can vary in length, but will always be below 100. Hence I want an oversized cell array to accommodate larger rows of strings. I want to put the row of strings into a specified row within the empty matrix, in my example code, I'm trying to put the row of stings into the first 41 columns in row 2....
I don't understand why the below code doesn't work:
MasterCellArray{2,1:41}=rowofstrings
or
MasterCellArray{2,1:41}=rowofstrings(1,41)
Any help is appreciated
2 个评论
the cyclist
2014-11-4
编辑:the cyclist
2014-11-4
What size and type of variable is rowofstrings?
Can you give a small example of the input and output you are expecting. Please don't just describe. Try to show what the MATLAB variables actually are.
An individual cell can hold an entire string, so I am not sure why you need 12x100. Are you trying to split the string, one character per cell?
采纳的回答
Matt Tearle
2014-11-4
If rowofstrings is a 1-by-41 cell array then your first line will work if you change the {} to ():
MasterCellArray(2,1:41) = rowofstrings
If not, then you'll have a problem... Using the {} on the left is going to fail because that returns 41 individual elements. If you use (), you're indexing into a 1-by-41 cell array that is a portion of MasterCellArray. That means the expression on the right of the = must also be a 1-by-41 cell array. So if rowofstrings is a (1-by-41) char array, for example, you could do something like:
MasterCellArray(2,1:41) = cellstr(rowofstrings')'
(This converts rowofstrings to a cell array, letter-by-letter, then assigns each cell to the appropriate element of MasterCellArray.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!