Create a structure of a field in the workspace
18 views (last 30 days)
Show older comments
Commented: Samy Alkhayat on 16 Aug 2022
I am trying to create a structure of all variables in the workspace that includes a field value of those variables.
For example, I have variables A, B, C, and I want to have:
A.Value = A;
I did this for all 200 variables in myworkspace and I am getting the error below:
Unable to perform assignment because dot indexing is not supported for variables of this type.
Can you please advice if there's more efficient way? Thanks in advance
Dyuman Joshi on 16 Aug 2022
Edited: Dyuman Joshi on 16 Aug 2022
You are overwriting numeric values (double precision) with struct values. That is not allowed and hence the error.
If all your variables are individually defined, then you will have to assign them manually. If they were in a matrix, we could have used for loop.
Assigning them to a single structure -
More Answers (1)
KSSV on 16 Aug 2022
You can save them into a matfile and access, as you like.
A = 1 ;
B = 2;
C = 3 ;
save Test.mat ;
S = matfile('Test.mat') ;
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!