Imagine the following structure:
A.B1 = 1:42;
A.B2 = 'Hello World!'
Now I want to perform some operations, but back up existing data in a new substructure.
A.B1.C1 = A.B1;
A.B1.C2 = mean(A.B1.C1);
These two lines (as an example) I want to add to the function, so my script will look like this:
A.B1 = 1:42;
A.B2 = 'Hello World!'
myfunction(A.B1)
and my workspace should look like this:
A =
B1: [1x1 struct]
B2: 'Hello World!'
A.B1 =
C1: [1x42 double]
C2: 21.5
But I am unable to create this function in such a way that my original structure is Anot destroyed. In addition, the entrance to my function can be W.X.Y, and I would like to receive W.X.Y.Z1and W.X.Y.Z2then. And also it can be a simple vector A = 1:42and should be A.B1, and A.B2subsequently.
Any tips?
- fieldnames assignin('base',...) - ?
: , inputname . , A , fieldnames, B1 B2, , "A". A inputname(1), 'A'. structs .
? , ...