Convert char to multiple cells, each cell takes one string

2 ビュー (過去 30 日間)
Zoe Zhang
Zoe Zhang 2011 年 9 月 20 日
I have a 1*121 char 'Runtime_Cur','Runtime_Prev','Id_Cur','Id_Prev','Description','PNL','PNL_Cur','valuedate_Cur','PNL_Prev','valuedate_Prev'
cellstr gives me a 1*1 cell, but I would like to get a 1*10 cell, each cell contains one string, so it will be: {'Runtime_Cur','Runtime_Prev','Id_Cur','Id_Prev','Description','PNL','PNL_Cur','valuedate_Cur','PNL_Prev','valuedate_Prev'}
ans =
Columns 1 through 6
'Runtime_Cur' 'Runtime_Prev' 'Id_Cur' 'Id_Prev' 'Description' 'PNL'
Columns 7 through 10
'PNL_Cur' 'valuedate_Cur' 'PNL_Prev' 'valuedate_Prev'
Could any one help? Thanks in advance :-)
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 9 月 20 日
What is the original variable, the 1*121 char? Can you put it in your question?

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

採用された回答

Walter Roberson
Walter Roberson 2011 年 9 月 20 日
Provided that the literal quote marks do not appear in the middle of a string:
STRING(STRING=='''') = [];
STRcells = regexp(STRING, ',', 'split');
  1 件のコメント
Zoe Zhang
Zoe Zhang 2011 年 9 月 20 日
Thanks so much, magic raccoon!

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 20 日
a='Runtime_CurRuntime_PrevId_CurId_PrevDescriptionPNLPNL_Curvaluedate_CurPNL_Prev';
size(a)
b=mat2cell(a,1,[10 10 20 20 18])
Those numbers determines how to split the long string into cells.
  1 件のコメント
Zoe Zhang
Zoe Zhang 2011 年 9 月 20 日
Thanks so much, that's what I want. But do u think there is a way of avoiding these numbers?

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by