Hello,
i want to use strings from a cell array as path. How can i do it?
I want to write a code, that loops over all my subfolders. The path to the folders are in my cell-array.
My code are:
if true
% code
dirs=regexp(genpath(currentpath),['[^;]*'],'match');
size_dirs=size(dirs);
for i=1:size_dirs(1,2)
data=dir([dirs(1,i),\*.tsv']); <<< here i want my subfolder from the cell-array in dirs!!
anzahl=numel(data);
.. do something
end
The error is: argument must contain a string. But in my cell-arrays are only strings :( can someone help??

답변 (1개)

ES
ES 2013년 10월 17일

1 개 추천

No.. dirs is a cell array of strings.
Type whos and you will see
dirs 1x28 7098 cell
modify your code slightly to
data=dir([dirs{i},'\*.tsv']);
to make it work.

댓글 수: 1

Jan
Jan 2013년 10월 17일
fullfile is slightly smarter than concatenating with a hardcoded file separator - this considers different operating systems and folders like "C:\" :
data=dir(fullfile(dirs{i}, '*.tsv'));

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2013년 10월 17일

댓글:

Jan
2013년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by