Borrar filtros
Borrar filtros

create structure array with eval

8 visualizaciones (últimos 30 días)
cemsi888
cemsi888 el 19 de Sept. de 2016
Editada: Stephen23 el 19 de Sept. de 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

Respuesta aceptada

Stephen23
Stephen23 el 19 de Sept. de 2016
Editada: Stephen23 el 19 de Sept. de 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 comentarios
cemsi888
cemsi888 el 19 de Sept. de 2016
Editada: cemsi888 el 19 de Sept. de 2016
it says invalid fieldname. Invalid field name: 'P1_1_30
Stephen23
Stephen23 el 19 de Sept. de 2016
Editada: Stephen23 el 19 de Sept. de 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'.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by