deleting entries across all fields of a structure

5 Ansichten (letzte 30 Tage)
Sankar Subbayya
Sankar Subbayya am 9 Okt. 2012
I have a datastructure docMetaS =
DOCUMENT_ID: [184899x1 int32]
DOCUMENT_PUBLISHER: [184899x1 int32]
LIST_PRICE: [184899x1 int32]
PRIMARY_CATEGORY: {184899x1 cell}
PAGES: [184899x1 int32]
index = [80:100]
I would the elements with indices from 80 to 100 for all the fields in the structure.
I know it is possible to do using docMetaS.DOCUMENT_ID(index) =[];
and so on for all the four elements.
Is there a elegant way to do this in one or two statements?
Thanks,
Sankar

Akzeptierte Antwort

Matt Fig
Matt Fig am 9 Okt. 2012
Bearbeitet: Matt Fig am 9 Okt. 2012
An example:
% Create a structure with multiple fields.
S.a = rand(1,100);
S.b = rand(1,100);
S.c = rand(1,100);
S.d = cellfun(@(x) rand,cell(1,100),'Un',0);
S % Show the structure, then delete some of it:
S = structfun(@(x) x([1:79 90:100]),S,'Un',0);
S % Show the reduces structure.
  1 Kommentar
Sankar Subbayya
Sankar Subbayya am 9 Okt. 2012
Hi Matt Fig,
Excellent Answer. This solves my problem. I did not know that structfunc is this powerful.
Thanks,
Sankar

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by