Error using readtable (line 318) Matlab R2021a
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I try to open my file and it answers me that
K>> t=readtable(sprintf('F:\\sub_%i.xlsx',n))
Error using readtable (line 318)
Search term must be a text or pattern scalar.
And when i only use the readtable function it says me that
K>> readtable
Error using readtable (line 318)
Not enough input arguments.
And when i open the readtable script, it opens that and the variable "ME" at the end seems to be the problem since it is not defined anywhere
function t = readtable(filename,varargin)
[varargin{1:2:end}] = convertStringsToChars(varargin{1:2:end});
names = varargin(1:2:end);
try
if any(strcmpi(names,"Format"))
t = matlab.io.internal.legacyReadtable(filename,varargin);
else
func = matlab.io.internal.functions.FunctionStore.getFunctionByName('readtable');
C = onCleanup(@()func.WorkSheet.clear());
t = func.validateAndExecute(filename,varargin{:});
end
catch ME
throw(ME)
end
If someone could help me it eould be really great,
thanks!
4 Kommentare
Cris LaPierre
am 28 Aug. 2023
Your code runs without errors here. I also checked in R2021a and again, it ran without error.
Can you provide more details about your system and setup? Perhaps try restarting MATLAB and seeing if just running the code below works for you as well?
n=1;
t=readtable(sprintf('sub_%i.xlsx',n))
function t = readtable(filename,varargin)
[varargin{1:2:end}] = convertStringsToChars(varargin{1:2:end});
names = varargin(1:2:end);
try
if any(strcmpi(names,"Format"))
t = matlab.io.internal.legacyReadtable(filename,varargin);
else
func = matlab.io.internal.functions.FunctionStore.getFunctionByName('readtable');
C = onCleanup(@()func.WorkSheet.clear());
t = func.validateAndExecute(filename,varargin{:});
end
catch ME
throw(ME)
end
end
Rik
am 28 Aug. 2023
N=1;
for n=1:N
s = sprintf('sub_%i',n);
t=readtable(sprintf('sub_%i.xlsx',n),'NumHeaderLines',0, 'ReadVariableNames',true);
end
As you can see, this code runs without error on R2023a.
What does the line below return on your machine?
clc,strrep(which('readtable','-all'),matlabroot,'')
Antworten (1)
dpb
am 28 Aug. 2023
Bearbeitet: dpb
am 28 Aug. 2023
t=readtable('sub_1.xlsx');
head(t)
t=readtable('sub_1.xlsx','numheaderlines',0,'readvariablenames',1);
head(t)
Seems just fine although as shown you don't need either input parameter for the "plain vanilla" file...I wondered if the two of telling it no header lines and to read variable names were, perhaps, fighting each other, but it appears it figured it out.
As for the filename generation, I'd suggest using something more like
dataDir='YourDataFolder';
d=dir(fullfile(dataDir,'sub*.xlsx')); % return the dir() struct matching files
for i=1:numel(d) % iterate over collection
t=readtable(fullfile(d(i).folder,d(i).name); % read each in turn
... do whatever with each here...
end
Whatever was the cause of the error in the original, it wasn't in what we've been able to see that you've posted.
Would need the actual script and data file that created the error to diagnose; what we can see is ok...
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!