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
dpb
2021년 6월 22일
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
2021년 6월 22일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!