Effacer les filtres
Effacer les filtres

modify and repalce structure fields

1 vue (au cours des 30 derniers jours)
Jeff Eriksen
Jeff Eriksen le 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

Réponses (1)

Sriram Tadavarty
Sriram Tadavarty le 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by