フィルターのクリア

modify and repalce structure fields

1 回表示 (過去 30 日間)
Jeff Eriksen
Jeff Eriksen 2020 年 3 月 22 日
回答済み: Sriram Tadavarty 2020 年 3 月 22 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by