0

How do I create an array in struct to keep track of all my_exp?

My code

my_exp=struct(x, y);
for i = 1:32
    my_exp.x= i;
    my_exp.y= i*i;
end
my_exp
  • @Adriaan I think the duplicate you picked is incorrect. The question wasn't about an array of structures, but an array *in* a struct – Paolo Jul 06 '20 at 14:02

1 Answers1

1

Make sure you initialize your structure properly. You want to do:

my_exp=struct('x',[],'y',[])
for i = 1:32
  my_exp.x= [my_exp.x i];
  my_exp.y= [my_exp.x i*i];
end
my_exp
Paolo
  • 21,270
  • 6
  • 38
  • 69