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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by