How to create a variable from cell array contents?
3 ビュー (過去 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 create a new variable as follows?
out = [x;y;var1;var2;var3];
2 件のコメント
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.
採用された回答
Nikolai Jakuba
2018 年 6 月 18 日
You can use struct:
for idx_cell = 1:size(mycell,1) out.(mycell{idx_cell})={}; end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!