How to write cell array contents into m-file as shown below?

3 ビュー (過去 30 日間)
Akbar
Akbar 2018 年 6 月 7 日
コメント済み: Akbar 2018 年 6 月 8 日
I have a cell Array vector as attached (length may vary). It contains variable names.
mycell =
5×1 cell array
{'x' }
{'y' }
{'var1'}
{'var2'}
{'var3'}
How to print it in m-file as follows?
out = [x;y;var1;var2;var3];
  3 件のコメント
Akbar
Akbar 2018 年 6 月 8 日
I just Need to print that cell in m-file as shown above.

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

採用された回答

Stephen23
Stephen23 2018 年 6 月 8 日
編集済み: Stephen23 2018 年 6 月 8 日
Printing the strings of a cell array to an open file (with id fid) is easy, just use a combination of sprintf and fprintf, something like this:
str = sprintf(';%s',mycell{:});
fprintf(fid,'out = [%s];\n',str(2:end));
Note that meta-programming (automatically writing code and running it) is quite inefficient.
  1 件のコメント
Akbar
Akbar 2018 年 6 月 8 日
It's very helpful! Danke!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by