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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 26 日
You don't need cellfun
F=fullfile(P,N)
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'
anu
anu 2016 年 8 月 29 日
Thanks a lot.

サインインしてコメントする。

その他の回答 (1 件)

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

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by