Error using readtable '.1(0a)' is not a recognized file extension. Unable to detect file type.
Afficher commentaires plus anciens
This is my script:
%{
Load data for exp 2.1
load all files
Calculate the quantitative EMG value for each data set
Generate mothods figure with raw EMG. integrated EMG, quant EMG
Generate a results figure with the quant EMMG before and after fatigue
%}
%%
clear all
% extract files that have '2.1' in them
files = dir("*2.1*");
S = struct;
figure(1);clf
t1 = tiledlayout('flow');
for a = 1:length(files)
T_name = ['Exp_'+ string(files(a).name)]; % creates dynamic name
S.(T_name) = readtable(files(a).name);
nexttile
plot(S.(T_name).Time_s_.S.(T_name).AI0HPF_V_)
title(strrep(T_name,'_',' '));
clear T_name
end
t1.Padding = 'compact';
t1.TileSpacing = 'compact';
And this is the error message I'm recieving:
Error using readtable
'.1(0a)' is not a recognized file extension.
Unable to detect file type. To read the file
as a specific file type, regardless of file
extension, use the 'FileType' name-value
pair.
Error in tutorialplots (line 26)
S.(T_name) = readtable(files(a).name);
My files are named "2.1(0a)" and so on and I guess I'm unsure of what the filetype actually is. The contents of the files look like .csv files. The column headers read "Time (s), AI0 HPF (V), AI0 MWSDF (V), AI1 HPF (V), AI1 MWSDF (V)".
Réponse acceptée
Plus de réponses (1)
the cyclist
le 23 Oct 2023
MATLAB can't autodetect the file type, and you're not sure either, so you can try to experiment. You can specify a ('Name','Value') argument pair, as mentioned in the documentation this section of the readtable documentation.
For example, you could try
readtable(files(a).name,'FileType','text')
since it seems CSV-ish.
There are more sophisticated ways to specify the file layout (e.g. textscan), but I would try a few file types first, and see if that works.
4 commentaires
hyu34gyd5
le 23 Oct 2023
Walter Roberson
le 23 Oct 2023
Is it correct that you are expecting the content of the file to be stored into S.Exp_2.1(0a) ? As in inside field Exp_2 of struct S, you would want a field named 1(0a) ?
hyu34gyd5
le 23 Oct 2023
Walter Roberson
le 23 Oct 2023
and you should makeing
filenames = {files.name};
to record the file names; and saving into a cell array of tables:
S = cell(length(filenames), 1);
for a = 1 : length(filenames);
S{a} = readtable(filenames{a});
end
This separates data from variable names.
You could put them together afterwards into a struct if you wanted,
SS = struct('filename', filenames(:), 'Data', S);
This would create a struct array with fields 'filename' and 'Data' if you had a particular reason to want to code as a struct array instead of as a pair of variables filenames and S
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!