modify and repalce structure fields

4 views (last 30 days)
Jeff Eriksen
Jeff Eriksen on 22 Mar 2020
Answered: Sriram Tadavarty on 22 Mar 2020
I have a structure ALL with 42 misc fields. One of these fields is a structure E with 4 fields (A,B,C,D), each of size N. I need to modify these fields and replace structure E with a new structure E that will have approximately N/4 elements.I am having difficult indexing the ABCD fields so I can manipualte them. I can do this for instance to extract the ALL.E.C field and print it to the comand window, but nothing I try will allow me to extrract it and put it into a double array so I can manipulate it.
ALL.E(1:end).C ----> prints to command window
I tried this
struct2cell(ALL.E(1:end).C) ---> error
but it said it would not work with arguments of 'double' Can someone please suggest a way I can achieve my goal?
-Jeff

Answers (1)

Sriram Tadavarty
Sriram Tadavarty on 22 Mar 2020
Hi Jeff,
You can try indexing as such
>> ALL.E.A % ALL is a structure with field E and field E has another field A
% To replace A field with 1/4 elements
>> ALL.E.A = rand(1,N/4); % Replace with the respective elements as you need
% Peform this for other fields B,C, and D
% TO replace the complete structure
>> ALL.E = F; % F is another structure
Hope this helps.
Regards,
Sriram

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!