How to create a variable from cell array contents?

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 create a new variable as follows?
out = [x;y;var1;var2;var3];

댓글 수: 2

Stephen23
Stephen23 2018년 6월 7일
편집: Stephen23 2018년 6월 7일
This approach will force you into writing slow, complex, buggy code. Read this to know why:
Rather than accessing variable names in the workspace, you should revise your concept and use simpler, more efficient, and more robust methods, e.g. indexing, structure+fieldnames, table+variables, etc.
Akbar
Akbar 2018년 6월 8일
편집: Akbar 2018년 6월 8일
Thank you for advice Stephen. I think I will go with tables then.

댓글을 달려면 로그인하십시오.

 채택된 답변

Nikolai Jakuba
Nikolai Jakuba 2018년 6월 18일

0 개 추천

You can use struct:
for idx_cell = 1:size(mycell,1) out.(mycell{idx_cell})={}; end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

2018년 6월 7일

답변:

2018년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by