Error using readtable: Must be a scalar logical value

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

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.
Thanks dpb.
Native file names are Master w EQ 00 deg.txt, Master w EQ 05 deg.txt, etc up to Master w EQ 90 deg.txt. The data in the files are three columns: Frequency, Level, and Phase. There are multiple spaces in the text file to delimit between columns when the file is output from our measurement system.
I did get it to work by just omitting the 'MultipleDelimsAsOne' because there were not multiple types of delimiters between values.
readtable([D0,filenametxt,' 0',num2str(deg(1,i)),' Deg.txt'])

댓글을 달려면 로그인하십시오.

 채택된 답변

dpb
dpb 2021년 6월 22일
"file names are Master w EQ 00 deg.txt, Master w EQ 05 deg.txt, etc up to Master w EQ 90 deg.txt."
d=dir('Master*deg.txt');
for i=1:numel(d)
tData=readtable(d(i).name);
% do whatever with each table in turn here
...
end
The 'MultipleDelimsAsOne' problem probably was related to the note/requirement:. "You must also specify the Delimiter option". although I've not tested that behavior.

추가 답변 (0개)

카테고리

제품

릴리스

R2020a

질문:

2021년 6월 22일

답변:

dpb
2021년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by