Azzera filtri
Azzera filtri

Can't acces existing struct

1 visualizzazione (ultimi 30 giorni)
Libros Construccion
Libros Construccion il 8 Dic 2016
Hi, I'm learning some about matlab. By now i'm trying to get the fields names by code with fieldnames(), but trying to fix it with Material.(s) by now.
This is a part of my code with the problem:
Material.Acero.Cuadrado.C_15x15=[1 1.5] %Creates the struct
Material.Acero.Cuadrado.C_15x15 %Just to verify it's existence
s=strjoin(t,'.') %Develop in another part of the code and returns for example 'Acero.Cuadrado'
class(s) %Just for check
size(s) %Just for check
Material.(s)
And returns the following:
Material =
Acero: [1x1 struct]
ans =
1.0000 1.5000
s =
Acero.Cuadrado.C_15x15
ans =
char
ans =
1 22
Reference to non-existent field 'Acero.Cuadrado.C_15x15'.
Error in test3>Datos (line 516)
Material.(s)
Error while evaluating Table CellEditCallback
I have manage to get just s='Acero' and it works fine. So it seems that Material.(s) is ignoring the dots and is taking ,for example, 'Acero.Cuadrado.C_15x15' as a complete field name and not subfields.
I have also trying the following codes:
s=sprintf('.%s',t{1:end-1},t{end})
--> Returns class:char and "non-existent field" even for s='Acero'
for i=2:1:col
s=strcat(s,'.',table2(row,i))
end
--> Returns class:cell and "Argument to dynamic structure reference must evaluate to a valid field name."
  2 Commenti
per isakson
per isakson il 8 Dic 2016
Modificato: per isakson il 8 Dic 2016
  • dots, ".", are not allowed in field names.
  • Try: Materials.('Acero').('Cuadrado').('C_15x15')
Libros Construccion
Libros Construccion il 8 Dic 2016
Modificato: Libros Construccion il 8 Dic 2016
Thanks! that works, I use this way:
fieldnames(handles.Material.(t{1}).(t{2}).(t{3})')
but i'm still thinking that Material.(s) was trying to read the whole s' content. I Know that dots are not allowed as field name cos that will crush the array syntax.
Another problem that confronted trying this was that fieldnames() must be inputed with obj not str, char or cell. But thanks again!

Accedi per commentare.

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