Error using readtable: Must be a scalar logical value
Show older comments
I am attempting to read in 19 different measurement files. The third line is the code that throws the error in the readtable function.
for i=1:18
if length(num2str(deg(1,i))) == 1
Tnow = table2array(readtable([D0,filenametxt,' 0',num2str(deg(1,i)),' Deg.txt'],'MultipleDelimsAsOne',1));
I get the error:
Error using readtable (line 198)
Must be a scalar logical value.
Below is the code for the readtable function. The throw(ME) code is line 198 that is referred too by the error. I read the above documentation for the function, and nothing defines or describes what ME is or how to define it.
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
I am thinking the error results from how I am defining the inputs of the readtable function, but I'm not sure what other syntax to change. Any help is appreciated.
2 Comments
dpb
on 22 Jun 2021
Tnow = table2array(readtable([D0,filenametxt,' 0',num2str(deg(1,i)),' Deg.txt'],'MultipleDelimsAsOne',1));
Don't need to try to play "MATLAB golf" (see how few lines one can write something in as a challenge) -- get one thing to work at a time...plus, once you have a table, there's no reason to make arrays of the same data--use the table variables directly.
Tnow=readtable([D0,filenametxt,' 0',num2str(deg(1,i)),' Deg.txt'],'MultipleDelimsAsOne',1);
Now, we don't know what any of the variables inside there are, but first we need to see if you've built a real qualified file name that makes sense, so show us all those missing pieces.
Then, while that is a doable way to create a file name, it's certainly not the neatest way to do so; in all likelihood you could use a call to dir() with a suitable wild card pattern and get a list of files can use directly.
Paul Bickel
on 22 Jun 2021
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!