2

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'

...

2 Answers 2

1
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}
% ...
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

if I do that it will pass all the names to first index location but I wan to put each name to next index of each other.
I am not sure what you mean. Can you post a more accurate example of your data and what you would like it to look like?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.