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

2 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by