I need to fill a column data with a specific value

6 visualizaciones (últimos 30 días)
Dushan Sandaruwan
Dushan Sandaruwan el 1 de Mzo. de 2021
Comentada: Dushan Sandaruwan el 2 de Mzo. de 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)

Respuesta aceptada

KSSV
KSSV el 1 de Mzo. de 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.
  1 comentario
Dushan Sandaruwan
Dushan Sandaruwan el 2 de Mzo. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by