modify and repalce structure fields

4 次查看(过去 30 天)
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

回答(1 个)

Sriram Tadavarty
Sriram Tadavarty 2020-3-22
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

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by