I need to fill a column data with a specific value
5 views (last 30 days)
Show older comments
Dushan Sandaruwan
on 1 Mar 2021
Commented: Dushan Sandaruwan
on 2 Mar 2021
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 Comments
Accepted Answer
KSSV
on 1 Mar 2021
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.
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!