Borrar filtros
Borrar filtros

Populate Cells of Structure Array with Empty Tables

5 visualizaciones (últimos 30 días)
Jon
Jon el 2 de Nov. de 2022
Editada: Matt J el 2 de Nov. de 2022
Hello,
I want to have a Structure Array with 1 x C structure array with N x 10 tables.
Since the total number of columns in the Structure Array varies with the imported data, I'm not sure how to accomplish this.
The first thing I did was make a zero-filled N x 10 table, with which I want to use to populate each cell of the Structure Array.
I wanted to do something like this next:
Table = zeros(N,10)
for i=1:C
Struc_Array.a(i) = Table
end
So essentially, this For Loop is used to A. Create the Structure Array to the appropriate size, and B. Fill each cell with the zero Table.
Would it be something like this instead (after reading this post --> I haven't tried it yet):
Table = zeros(N,10)
for i=1:C
Struc_Array(i).a = Table
end
Perhaps my main issue is with how Structure Arrays work and their syntax.
I watched this video, as well as look over many pages and forum posts about the topic.
Thanks.

Respuestas (1)

Matt J
Matt J el 2 de Nov. de 2022
Editada: Matt J el 2 de Nov. de 2022
This might be what you want:
N=3; C=4;
T = array2table(zeros(N,10));
[Struc_Array(1:C).a]=deal(T);
Struc_Array.a
ans = 3×10 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 ____ ____ ____ ____ ____ ____ ____ ____ ____ _____ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ans = 3×10 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 ____ ____ ____ ____ ____ ____ ____ ____ ____ _____ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ans = 3×10 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 ____ ____ ____ ____ ____ ____ ____ ____ ____ _____ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ans = 3×10 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 ____ ____ ____ ____ ____ ____ ____ ____ ____ _____ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by