フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error with importdata when looping through files in folder

1 回表示 (過去 30 日間)
Nicola Fairbairn
Nicola Fairbairn 2019 年 8 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all,
I'm currently trying to build a script that will run through a folder full of awkward .txt files that need converting via excel to .csv, whilst stripping out some unwanted cells that contain unwanted data to give me a 512 x 16 table of values and saving these in a new folder as .csv, although I keep getting an importdata error as it's unable to open the files.
I've had a look through my code but can't find the issue exact, but I have a feeling it might be something to do with strcat and fullfile as I've had that issue before.
Any help would be appreciated. Thanks!
data_path = 'C:\Users\nicol\Desktop\RAII-H16-F11-HM2\Fat\';
% specify where to save smoothed files
new_path = strcat(data_path, 'csvcropped/');
if ~exist(new_path, 'dir')
mkdir(new_path);
end
search_string = fullfile(data_path, '*.txt');
% find all files matching search string
files = dir(search_string);
for i = 1:numel(files)
filename = files(i).name;
name = regexprep(filename, '.txt', '');
raw_data = importdata(filename);
text_data = raw_data.textdata;
cropped_data = text_data(25:536);
tmp = cellfun(@(x)regexprep(x, '(Pixel\s+\d{1,3}:\s+)', ''), cropped_data, 'UniformOutput', false);
data_cell = cellfun(@(x)regexp(x, '\d+', 'match'), tmp, 'UniformOutput', false); clear tmp;
processed_data = array2table(str2double(table2array(cell2table(data_cell))));
new_filename = [name '.csv'];
writetable(data, strcat(new_path, new_filename), 'WriteVariableNames', false);
end
  2 件のコメント
Neuropragmatist
Neuropragmatist 2019 年 8 月 5 日
What is the error?
Srivardhan Gadila
Srivardhan Gadila 2019 年 8 月 8 日
Can you please mention what is the exact error you are getting and at what line?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 8 日
raw_data = importdata( fullfile(data_path, filename));
I know that you do
search_string = fullfile(data_path, '*.txt');
but remember that the name field of the output of dir() is only the basic file name without any directory part.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by