Eren Golge
Eren Golge

Reputation: 790

Converting a struct array to string array including one of the property of the struct

I have a struct array Imgs and it includes following properties of image files inside each struct.

name
date
byte
isdir
datenum

now I want to create a new string array img_names that includes the only names of the above struct array. I am really a newbie about matlab and I don't get how to do it.

So I want to have a array like in that structure.

img_names[1] = 'file-1.jpg'

img_names[2] = 'file-2.jpg'

img_names[3] = 'file-3.jpg'

...

Upvotes: 2

Views: 1636

Answers (2)

Gunther Struyf
Gunther Struyf

Reputation: 11168

img_names = arrayfun(@(x) x.name,Imgs,'uni',false)

produces a cell array containing the names. You can then access each name using:

img_names{1}
img_names{2}
% ...

Upvotes: 1

AGS
AGS

Reputation: 14498

>> img_names=sprintf('%s\n',Imgs.name);

Upvotes: 1

Related Questions