# Refer to structure names

1 view (last 30 days)
Joanna Przeworska on 30 Mar 2021
Hi,
Suppose I have a structure A with a, b, c, d tables inside. My aim is to use names of tables within structure A (a, b, c, d) to create new tables in structure B. I tied to do this in the following way, however it does not work. Any ideas how to corect it?
B.(fieldnames(A)'){1} = table1
B.(fieldnames(A)'){2} = table2
....

Stephen Cobeldick on 30 Mar 2021
Edited: Stephen Cobeldick on 30 Mar 2021
Joanna Przeworska on 1 Apr 2021
Best regards, JP

Matt J on 30 Mar 2021
args = [fieldnames(A).'; {table1, table2, table3,...}]
B=struct(args{:})
Joanna Przeworska on 31 Mar 2021
Dear Matt,
Thank you for your response, whowever this is not exactly what I wanted to receive.

Image Analyst on 30 Mar 2021
"Suppose I have a structure A with a, b, c, d tables inside. My aim is to use names of tables within structure A (a, b, c, d) to create new tables in structure B."
So, why does this not work?
B = A;
New structure B will have all the same fields (a, b, c, and d) as existing structure A with the same names. Each field in the structure will have the same table as in A, which is what it seemed like you were trying to do when you assigned the tables. This also means that all the columns names of the tables of structure B will match the column names from the tables of structure A.
Joanna Przeworska on 31 Mar 2021
In my exercise, my goal is to dynamically refer to the field names of structure A in order to store the calculation in a different structure B, but with a name taken from structure A.
I don't know if I made it clear what I mean.