フィルターのクリア

Problems about extracting all the data files

1 回表示 (過去 30 日間)
Yixin Shao
Yixin Shao 2019 年 2 月 6 日
コメント済み: Yixin Shao 2019 年 2 月 7 日
%This function is used to get all the data files to be processed
%fdir--the directory of files to be processed
function ufnames = getdatafile(fdir,debug)
close all;
if ~isdir(fdir)
error('FOLDER DOES NOT EXIST')
end
fnames_all = dir(fdir); %GET LIST OF FILES IN fdir FOLDER
if debug
fprintf('\n')
fprintf('\nNames of files inside given directory:\n')
fnames_all
fprintf('\n')
end
%EXTRACT FILE NAMES TO BE PROCESSED
ufnames = [];
sfnames_all = size(fnames_all);
for i = 1:sfnames_all(1)
[path, fname, ext] = fileparts(fnames_all(i).name);
if strcmpi(ext, '.ovf')
ufnames = char(ufnames, [fdir fname ext]); %IF OVF FILE SAVE FULL NAME
end
end
ufnames = ufnames(2:end,:);
if debug
fprintf('\n')
fprintf('\nNames of only ovf files inside given directory:\n')
ufnames
fprintf('\n')
end
end
This is my code, and I want to use this function to wxtract all the data files to be processed. But when I run it, I always get an error at"ufnames = char(ufnames, [fdir fname ext]);", which says"Error using char, Inputs must be character arrays." How can I solve it? How to append the new file name into the array in each loop?

採用された回答

Shawn Duenas
Shawn Duenas 2019 年 2 月 6 日
編集済み: Shawn Duenas 2019 年 2 月 6 日
replace that line with:
ufnames = [ufnames, [fdir fname ext]];
it seems like you're trying to concatenate everything together. into one long string.
try this for better coding style:
ufnames = [ufnames, fullfile(fdir, [fname, ext]), newline];
Also try these lines of code to replace much of the script:
fnames_all = dir(fullfile(fdir,'*.ovf'));
ufnames ={fnames_all.name}';
  2 件のコメント
Yixin Shao
Yixin Shao 2019 年 2 月 7 日
Thank you very much! Could I ask one more question? How can I make the newly appended file name into another row, not another column? Since the "newline" here just add an extra column.
Yixin Shao
Yixin Shao 2019 年 2 月 7 日
I changed the comma into semicolon and it works. THX

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by