I have a structure in matlab that has a value of <1x1 struct>., its name is figurelist.
Inside that structure, there is a field called images. Inside images, I have 25 images that have the name img1, img2, img3, ..... , img25.
Now I made a for loop to extract those images, I basically did:
For K=1:25
image(figurelist.images.imgK)
PAUSE(0.25)
End
This unfortunately doesnt work. I get an error saying :
??? Reference to non-existent field 'imgK'.
Is it possible to extract such info using a loop from a structure? Or am I doing something wrong?
Thanks.
You would have to do something like this:
Since the field name is a function of your loop variable, you have to construct a string for the field name. The function INT2STR converts the value of your loop variable
Kto a character string, which is then appended to'img'to create the string for the field name. Then the dynamic field reference syntax (.( )) is used to access the field value using that string.A couple of nice examples of using dynamic field names can be found on Loren’s blog and Doug’s blog.