How to to create combined structure array with dynamic defined variable name?

Hi i used dynamic variable name to create structures. it works really good. after that i would like insert my measurement results(which are double arrays in to this structure) i mean
messung{i}.g (messung{i}=character)
it works really good with assignin too. What i did is:
% for i=1:length(handles.data)
aktuelpos=handles.data(i)
%set(handles.listbox1,'String',handles.data);
messung{i}=sprintf('P_%u_%u',handles.Posen.Position(i),handles.Posen.posen(i));
end
% assignin('base',messung{i},g)
Now i would like to concentrate created structure array in other array. Target: S.messung{i} The problem is messung{i} is a character array and messung{i}.a etc does not work unfortunately. I used eval too but i did not create below defined structure form.
% eval(['S.messung{1}', =messung{1}'])
Could u please help me? best regards

6 件のコメント

Stephen23
Stephen23 2016 年 6 月 17 日
編集済み: Stephen23 2016 年 6 月 17 日
Are you getting any error messages? If so, what ones? Can you please tell us what your code does when you try to run it.
cemsi888
cemsi888 2016 年 6 月 17 日
編集済み: Stephen23 2016 年 6 月 17 日
% assignin('base',messung{1},g);
evalin('base',erg,'erg.messung{1}')
error:undefined function or variable erg
ı have to reach output of the assignin function and then i can concentrate in erg.but how can i do this ı have not any idea
Stephen23
Stephen23 2016 年 6 月 17 日
Please give the complete error message. This means all of the red text.
cemsi888
cemsi888 2016 年 6 月 17 日
Undefined function or variable 'erg'.
Stephen23
Stephen23 2016 年 6 月 17 日
編集済み: Stephen23 2016 年 6 月 17 日
Aaah, what an informative error message. Of course that is what you get when you choose buggy and slow operators like eval and assignin. What you have a perfect example of why using these commands is such a bad idea (no matter how much beginners love using them): obfuscated, unclear code, buggy, cryptic, hard to debug.
You could either:
  1. learn why these commands are slow and buggy, and replace them with more reliable methods of passing data around, or
  2. try to get them working.
Which would you prefer?
cemsi888
cemsi888 2016 年 6 月 17 日
2 i solve my problem
% eval(sprintf('S.%s = 4',meinmappe{1}));
ı know eval is really slow function but another solution i could not find. anyway thanx

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

回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2016 年 6 月 17 日
Hi,
if I understand correctly, you are looking for dynamic field names:
S.(messung{1}) = messung{1};
Titus

カテゴリ

ヘルプ センター および File ExchangeData Types についてさらに検索

質問済み:

2016 年 6 月 17 日

回答済み:

2016 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by