How to store strings into array?

2 次查看(过去 30 天)
anu
anu 2016-8-26
评论: anu 2016-8-29
I am reading filename from directory and want to store it into array.
srcFiles = dir('E:\abc\*.bmp'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('E:\abc\',srcFiles(i).name);
names(i,:)=filename;
end
I am getting following error ??? Undefined function or variable 'names'.
  3 个评论
Stephen23
Stephen23 2016-8-26
@Azzi Abdelmalek: thank you, I changed the comment.

请先登录,再进行评论。

采纳的回答

Adam
Adam 2016-8-26
I wouldn't expect you to be getting that specific error, but strings need to be stored in a cell array, not a numeric array generally:
names{i} = filename;
You may want to presize names though as
names = cell.empty( length(srcFiles), 0 );
or something similar.
  5 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2016-8-27
I think the reason is obvious, your cell array is a row vector, then you have just to transpose it
names=names'

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-26
names=fullfile('E:\abc\',{srcFiles.name})

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by