how to value nan number in a vector? and how to do the same calc in a 2d matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
--I have a vactor where some values are NaN.The results are on the following plot(in the red box the nan) :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145579/image.png)
--I was wondering if there is a way to assume the values so it will be something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145580/image.png)
---Also how to do the same procedure if some values of 2d matrix is NaN? Thanks in advance.
댓글 수: 0
채택된 답변
Andrei Bobrov
2014년 10월 2일
편집: Andrei Bobrov
2014년 10월 2일
Let X your array with NaN's
ii = ~isnan(X);
i0 = reshape(1:numel(X),size(X));
Xout = interp1(i0(ii),X(ii),i0);
추가 답변 (1개)
Iain
2014년 10월 2일
You've got an x & y vector, so this would remove the NaNs:
nans = isnan(Y) || isnan(X);
Y(nans) = [];
X(nans) = [];
You'll need to interpolate if you want the X & Y for all the values of your original X.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!