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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by