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
1
  • @Adriaan I think the duplicate you picked is incorrect. The question wasn't about an array of structures, but an array in a struct Commented Jul 6, 2020 at 14:02

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

This solved the issue of it not running but how do I prevent the for loop from over writing the old values?
@asasasasas you want an array of structs? just do that then!
@asasasasas See edit