How to store strings into array?

2 Ansichten (letzte 30 Tage)
anu
anu am 26 Aug. 2016
Kommentiert: anu am 29 Aug. 2016
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 26 Aug. 2016
You don't need cellfun
F=fullfile(P,N)
Stephen23
Stephen23 am 26 Aug. 2016
@Azzi Abdelmalek: thank you, I changed the comment.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam
Adam am 26 Aug. 2016
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 27 Aug. 2016
I think the reason is obvious, your cell array is a row vector, then you have just to transpose it
names=names'
anu
anu am 29 Aug. 2016
Thanks a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by