Azzera filtri
Azzera filtri

create structure array with eval

8 visualizzazioni (ultimi 30 giorni)
cemsi888
cemsi888 il 19 Set 2016
Modificato: Stephen23 il 19 Set 2016
hi guys First of all I know that it is really inefficient to create structure array with eval.However i did not find a simple solution to create structure array for my evaluation tool. I am now programming kuka robot and for each position I obtain values and have to save my results in this array. Finally i would like to create main array which contains all positions and related results. However,Matlab saves just last Position (it means: Matlab overwrites) Main structure array=Ergebnisse How can solve this Problem? Could you please help me? I add following my codes:
eval(sprintf('Ergebnisse.P%d_%d_%d =[aus_fft] ',Position,PointId,Pose));
if i==it
auslenkung_ges=auswertung_2(auslenkung,i,choice);
eval(sprintf('Ergebnisse.auslenkung_Position_%d =[auslenkung_ges] ',Position));
end

Risposta accettata

Stephen23
Stephen23 il 19 Set 2016
Modificato: Stephen23 il 19 Set 2016
This is simple using dynamic fieldnames, and you do not need eval:
Ergebnisse.(sprintf('auslenkung_Position_%d',Position)) = ...
Dynamic fieldnames are explained clearly in the documentation:
And I notice that dynamic fieldnames been explained to you before in several of your earlier questions, but you keep on persisting in using the slowest and buggiest eval-based solutions... and then get stuck because your code is slow and buggy and hard to get working properly... maybe it would be a good time to understand why bad design decisions actually really do make your code worse.
Addendum: You might like to use a non-scalar structure, which would be much faster and simpler:
  2 Commenti
cemsi888
cemsi888 il 19 Set 2016
Modificato: cemsi888 il 19 Set 2016
it says invalid fieldname. Invalid field name: 'P1_1_30
Stephen23
Stephen23 il 19 Set 2016
Modificato: Stephen23 il 19 Set 2016
Check how you generate the fieldname string:
>> Ergebnisse.('P1_1_30') = 3
Ergebnisse =
P1_1_30: 3
>> Ergebnisse.('''P1_1_30') = 3
Invalid field name: ''P1_1_30'.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by