I need to loop through a set of structures/fields within a structure, 'dicom', to obtain specific reference numbers stored within the structure.
The reference number(s) that I am looking for can be called by: dicom.DVHSequence.Item_1.DVHReferencedROISequence.Item_1.ReferencedROINumber
However, the Item_# will change each time I call a reference number.
I have used sprintf to change the Item_# that I am calling:
ref_ROI_num_file_name = sprintf('dicom.DVHSequence.Item_%i.DVHReferencedROISequence.Item_%d.ReferencedROINumber',h,h)
with a for loop to increment 'i' (which works).
However, after I use sprintf, I cannot seem call the field name. I have tried getfield() to no avail.

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 19 日

0 投票

You can not use getfield() to get to the field more then one level below.
For example:
clear a;
a.item_1.b.c.item_1.d=1;
You can not run:
y=getfield(a,'item_1.b.c.item_1.d')
but you can use dynamic fieldnames:
ItemField=sprintf('item_%d',1);
y=a.(ItemField).b.c.(ItemField).d

1 件のコメント

Tara Hackel
Tara Hackel 2011 年 9 月 28 日
Wonderful! Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で DICOM Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by