Struct to matrix

2 ビュー (過去 30 日間)
Nuno Fernandes
Nuno Fernandes 2011 年 9 月 3 日
Hello
i have something like
{'C1' 'C3/A2' 'C4' } and i want to have
a=[C1;C3/A2;C4]
how can i do this?
Thanks
  1 件のコメント
Paulo Silva
Paulo Silva 2011 年 9 月 3 日
can you explain what's the purpose, correct me if I'm wrong, the cell got a string for each element but the array has variables?

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

回答 (2 件)

Paulo Silva
Paulo Silva 2011 年 9 月 3 日
C1=1;C3=3;A2=2;C4=4;
s={'C1' 'C3/A2' 'C4' }
m=[cellfun(@eval,s)] %evaluate the calculations of the string
If this assumption isn't correct I really don't know what you want because things like this ['C1' 'C3/A2' 'C4'] are just a string not one array, also ['C1';'C3/A2';'C4'] isn't valid.
PS: Before someone hits me in the head with one hammer lol :D for using the eval function, I do know it's a lame solution but right now I don't remember of a better solution.

Walter Roberson
Walter Roberson 2011 年 9 月 3 日
Your meaning is not clear. Possibly you are wanting
s={'C1' 'C3/A2' 'C4' };
s(:)
or perhaps you want
char(s(:))
or perhaps something else entirely.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by