필터 지우기
필터 지우기

Undefined function or variable 'isnan'

조회 수: 8 (최근 30일)
Carver Nabb
Carver Nabb 2019년 1월 7일
댓글: Walter Roberson 2021년 4월 19일
I am met with the error "Undefined function or variable 'isnan'" when running this code:
%counter = 1:4
%a is a 220x4 cell
%data is a 220x4 double
for i = size(a, 1)
pairs = [];
pairs(:,1) = counter;
pairs(:,2) = data(i,:);
pairs = pairs(~isnan(pairs(:,2),:));
slope(i) = polyfit(pairs(:,1),pairs(:,2),1);
end
I can't seem to figure out exactly why. Is the way I'm using the NOT operator?
  댓글 수: 3
Carver Nabb
Carver Nabb 2019년 1월 7일
Screen Shot 2019-01-07 at 2.54.36 PM.png
nanren888
nanren888 2019년 1월 7일
As Walter says; It is complaining about the two-parameter isnan(x,y) that you've invented :)

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 7일
You have
pairs = pairs(~isnan(pairs(:,2),:));
You want
pairs = pairs(~isnan(pairs(:,2)),:);
  댓글 수: 21
Carver Nabb
Carver Nabb 2019년 1월 8일
Thank you, this does produce non-zero values. However, they are not the correct slopes, for example, I know the first slope ought to be 3.6, and the last, -4.6. However the first value returned with this code is 113.
Carver Nabb
Carver Nabb 2019년 1월 8일
I figured it out! Walter and Jan, thank you so much for the help. I do appreciate it.

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

추가 답변 (2개)

Jan
Jan 2019년 1월 7일
Although I assume that Walter hit the point already, I suggest to use teh debugger to identify such problems. Type in the command window:
dbstop if error
Now run the code again until it stops. Check the currently processed line by evaluating it piecewise:
% pairs = pairs(~isnan(pairs(:,2),:))
pairs(:,2)
~isnan(pairs(:,2),:) % <- This should fail already
pairs(~isnan(pairs(:,2),:))
As Walter has said already, isnan(x, :) is meaningful only, if it is an array. Otehrwise using the colon as second input is not valid, if the function isnan() is meant. The error message "Undefined function or variable 'isnan'" is not really clear here. But splitting the commands into parts using the debugger helps to understand the problem.

Kholoud Alzoubi
Kholoud Alzoubi 2021년 4월 19일
Undefined function or variable 'textdata'.
Error in KopackRFNNGOA (line 15)
x1=textdata(~isnan(textdata)); %temperature
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 4월 19일
Not enough context.
You are trying to use a variable named textdata that has not been assigned to.
Also, the variable name would tend to suggest that the variable is not expected to hold numeric data, so isnan() is questionable here.

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

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by