deleting entries across all fields of a structure

5 ビュー (過去 30 日間)
Sankar Subbayya
Sankar Subbayya 2012 年 10 月 9 日
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

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 9 日
編集済み: Matt Fig 2012 年 10 月 9 日
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 件のコメント
Sankar Subbayya
Sankar Subbayya 2012 年 10 月 9 日
Hi Matt Fig,
Excellent Answer. This solves my problem. I did not know that structfunc is this powerful.
Thanks,
Sankar

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by