I need to fill a column data with a specific value
조회 수: 6 (최근 30일)
이전 댓글 표시
I have data set
X=[1:1100];
first I need to make this one 'nan', then need to fill this data set with a specific values
A B
830 4.992
839 5.009
845 5.02
784 4.886
753 4.832
750 4.827
676 4.755
666 4.752
720 4.792
868 5.078
856 5.041
776 4.865
569 4.773
609 4.742
625 4.755
% so here A is the position in data line 1:1100, I need to fill above data set (X) with accordingly with (B=Sea level)
댓글 수: 0
채택된 답변
KSSV
2021년 3월 1일
Let data be your m*2 data.
x = data(:,1) ;
y = data(:,2) ;
y0 = y ;
% idx = A your indices which should be nan
y(idx) = NaN ;
x(idx) = [] ;
% use interp1 to get the NaN values
y(idx) = interp1(x(~idx),y(~idx),x(idx))
% plot
plot(x,y0,'r',x,y,'b')
legend('original','interpolated')
Also have a look on fillmissing.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!