I need to fill a column data with a specific value

조회 수: 6 (최근 30일)
Dushan Sandaruwan
Dushan Sandaruwan 2021년 3월 1일
댓글: Dushan Sandaruwan 2021년 3월 2일
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)

채택된 답변

KSSV
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.
  댓글 수: 1
Dushan Sandaruwan
Dushan Sandaruwan 2021년 3월 2일
Thank you very much for your kind answer. But its not clear to me.
I have a data set tide= [1100,2] =(number, tide) , number is from 1 to 1100.
I just need to extract some specific tide values according to the number positon like (what is tide at
601 626 652 681 711 742 991 1036 601 616 631 647 781 796 811 ) from this data set, and then the rest of the data shoul be nan.
then the final out put also should have the same size like A, but only perticular tide values and rest with nan.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by