sprintf + calling value in nested structure

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.

 Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 19 Sep. 2011

0 Stimmen

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

Weitere Antworten (0)

Kategorien

Mehr zu DICOM Format finden Sie in Hilfe-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