Can't acces existing struct

1 次查看(过去 30 天)
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 个评论
per isakson
per isakson 2016-12-8
编辑:per isakson 2016-12-8
  • dots, ".", are not allowed in field names.
  • Try: Materials.('Acero').('Cuadrado').('C_15x15')
Libros Construccion
编辑:Libros Construccion 2016-12-8
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!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by