フィルターのクリア

add string to matrix/ array in loop

2 ビュー (過去 30 日間)
D.
D. 2011 年 4 月 15 日
I wrote this function to get the full paths of all files in a specific folder:
function [ paths ] = getPaths(folder)
%GETPATHS Get full path of files containing a given folder
filelist = dir(folder);
filenames = {filelist.name};
paths = zeros(numel(filenames),1);
for k=3:numel(filenames)
[pathstr, name, ext] = fileparts(filenames{k});
current_path = [folder pathstr name ext];
paths(k) = current_path;
end
end
I get the error message:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> getPaths at 10
paths(k) = current_path;
How can I add string to matrix/ array in loop?

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 4 月 15 日
fldr = 'C:\Users\Oleg\Desktop\';
s = dir(fldr);
strcat(fldr, {s(~[s.isdir]).name})
  1 件のコメント
D.
D. 2011 年 4 月 18 日
this works with a '\' between path and file:
fldr = 'C:\Users\Oleg\Desktop\';
s = dir(fldr);
strcat(fldr, '\', {s(~[s.isdir]).name})
thank you!

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 4 月 15 日
can so
...
paths = cell(numel(filenames),1);
for k=3:numel(filenames)
[pathstr, name, ext] = fileparts(filenames{k});
paths(k) = {folder pathstr name ext};
end
...

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by