I need to fill a column data with a specific value
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuesta aceptada
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.
Más respuestas (0)
Ver también
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!