How to assign NaN to consecutive elements of a vector, in intervals defined by a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Paramonte
el 5 de Jun. de 2020
Comentada: Tommy
el 7 de Jun. de 2020
Hello there!
supose we have a vector x=1:12
and we have a controling matrix as this:
z=[2 4; 6 8; 10 11]
We want to assign NaN in x in the intervals in z for 2 to 4, 6 to 8 and 10 to 11, in order to get:
x_new= [ 1 NaN NaN NaN 5 NaN NaN NaN 9 NaN NaN 12]
Many thanks in advance for your time
2 comentarios
Respuesta aceptada
Tommy
el 5 de Jun. de 2020
Try this:
N = numel(x);
idx = any((1:N >= z(:,1) & 1:N <= z(:,2)));
x(idx) = NaN;
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre NaNs 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!