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

 採用された回答

Walter Roberson
Walter Roberson 2011 年 7 月 23 日

0 投票

rowHeaders = YourCellArrayName;
That is all you need: that is already equivalent to
rowHeaders = {YCAN{1}, YCAN{2}, YCAN{3}, ...};

2 件のコメント

Jason
Jason 2011 年 7 月 23 日
How would this be adapter where there are a variable number of elements in the array.
Thanks
Walter Roberson
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
Fangjun Jiang 2011 年 7 月 22 日

0 投票

You mean this?
a={'xx1 xx2 xx3 xx4'};
b=regexp(a{1},'\s','split')

3 件のコメント

Jason
Jason 2011 年 7 月 22 日
Not quite, my string is actially a cell array of size 1x4, so the first element is xx1, the 2nd is xx2 and so on.
Fangjun Jiang
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?
Jason
Jason 2011 年 7 月 22 日
I multiselect .txt files that have number name sin the format xx1, xx2 etc. I then put all of the selected files into a cell array.
Sometimes there are 12 files, sometimes 6 and sometimes 1 or 2.
I want to be able to take the cell array that has all the filenames in and put them into a rowheader in a uitable.

サインインしてコメントする。

Titus Edelhofer
Titus Edelhofer 2011 年 7 月 22 日

0 投票

or similarly using textscan:
b = textscan('xx1 xx2 xx3 xx4', '%s');
b = b{1}
Titus

カテゴリ

ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by