How can I properly index a table using isnan? (R2020a)

조회 수: 4 (최근 30일)
Ritchie Yu
Ritchie Yu 2020년 3월 28일
댓글: Ritchie Yu 2020년 3월 29일
I am writing multiple tables to an Excel spreadsheet, and do not want previously added tables to be overwritten. As such, I have created the following code. The variable R is a 14x11 table completely filled with NaN as my stated readtable range in Excel is currently empty. I have preceding code which uses manually specified filepaths to extract data from files and create the tables.
R = readtable('rangedata.xlsx',...
'Range','A2:K15',...
'ReadVariableNames',false)
if isnan(R(1,1))
writetable(T,'rangedata.xlsx','sheet',1,'Range','A2:B15');
elseif isnan(R(1,4))
writetable(T,'rangedata.xlsx','sheet',1,'Range','D2:E15');
elseif isnan(R(1,7))
writetable(T,'rangedata.xlsx','sheet',1,'Range','G2:H15');
else, isnan(R(1,10))
writetable(T,'rangedata.xlsx','sheet',1,'Range','J2:K15');
end
When running the script, I encounter the error "Check for missing argument or incorrect argument data type in call to function 'isnan'." I have tried changing all my index formatting to the following format, where Var1 is the name of the first variable, but that has not worked either.
if isnan(R(1,{'Var1'}))
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 3월 28일
isnan(R{1,1})
isnan(R.Var1(1))
isnan(R{1,'Var1'})
Ritchie Yu
Ritchie Yu 2020년 3월 29일
Thanks!

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

채택된 답변

Peng Li
Peng Li 2020년 3월 28일
Either use dot notion or {} pair to access a table element.
Try R.Var1(1) for example.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by