Cell array of Cells to Cell array of Strings

20 ビュー (過去 30 日間)
Brian
Brian 2011 年 12 月 27 日
Hopefully this is a fairly simple question, but I am new to Matlab and am having difficulty converting a cell array of cells to a cell array of strings. What I have is a cell array (z_TestImport) that contains a 1x2 array of cells. What I'd like is a cell array of strings.
How do I go about doing this?
If it would make it even easier I am arriving at the cell array of cells by using the import function below. Maybe the cell array of cells can be avoided during the import.
z_TestImport = textscan(z_Test,'%q %q','HeaderLines',1);
Thanks a lot, Brian

採用された回答

Matt Tearle
Matt Tearle 2011 年 12 月 27 日
Ah yes. This is a classic.
data = [z_TestImport{:}];
is probably what you're looking for.
The other option is to use the CollectOutput option to textscan (set it to true). However, you still get a cell containing all the data, so you're still left with a line like
data = z_TestImport{1};

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 12 月 27 日
Please recheck what you have written. If z_Test is a 1 x 2 array of cells, then you would not be able to use it as the first argument to textscan(), as the first argument to textscan() must be either a file identifier or a plain string.
If z_Test is instead a file identifier or a string, then z_TestImport would be a cell array with two columns, each of which was a cell array of strings -- the arrangement you describe z_Test as being. Try
[z_TestImport{1},z_TestImport{2}]
  1 件のコメント
Brian
Brian 2011 年 12 月 27 日
Sorry about that - I edited the original question

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by