Cell array
1 次查看(过去 30 天)
显示 更早的评论
If I have a cell array that consists of 1 row by n columns such as and each entry has text of the form
xx1 xx2 xx3 xx4
How can I create a single string that has each entry comma seperated. I need to create this format to enable Rowheaders for a UItable.
i.e. rowHeaders = {'xx1','xx2',xx3','xx4'};
thanks
0 个评论
采纳的回答
Walter Roberson
2011-7-23
rowHeaders = YourCellArrayName;
That is all you need: that is already equivalent to
rowHeaders = {YCAN{1}, YCAN{2}, YCAN{3}, ...};
2 个评论
Walter Roberson
2011-7-23
No adaptation needed, as long as the number of elements in the cell array matches the number of row headers you need.
When YCAN is a cell array of strings, then YCAN{1} is, for nearly every purpose in MATLAB, the same thing as writing the literal string at that point. YCAN{:} is, for nearly all purposes, the same thing as writing all of the literal strings at that point, separated by commas. {YCAN{:}} would thus be the same thing as writing {'xx1', 'xx2','xx3' } and so on. And just naming the cell array, YCAN, is the same thing as {YCAN{:}} . So all you need to do is write the cell array name if it is already initialized to the strings you want.
更多回答(2 个)
Fangjun Jiang
2011-7-22
You mean this?
a={'xx1 xx2 xx3 xx4'};
b=regexp(a{1},'\s','split')
3 个评论
Fangjun Jiang
2011-7-22
You mean a={'xx1' 'xx2' 'xx3' 'xx4'}? Then what processing do you need? Could you just update your question to include of your example input and output?
Titus Edelhofer
2011-7-22
or similarly using textscan:
b = textscan('xx1 xx2 xx3 xx4', '%s');
b = b{1}
Titus
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!