add string to matrix/ array in loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
Oleg Komarov
am 15 Apr. 2011
fldr = 'C:\Users\Oleg\Desktop\';
s = dir(fldr);
strcat(fldr, {s(~[s.isdir]).name})
Weitere Antworten (1)
Andrei Bobrov
am 15 Apr. 2011
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
...
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!