Borrar filtros
Borrar filtros

How could I write in a vector something in a position different to a given one?

2 visualizaciones (últimos 30 días)
v = [1,2,3,4,5]
idx = 3;
What I would like to do is get v = [NaN, NaN, 3, NaN, NaN];
How could I do it?

Respuesta aceptada

KSSV
KSSV el 15 de Oct. de 2021
v = [1,2,3,4,5];
idx = 3;
iwant = NaN(size(v)) ;
iwant(idx) = v(idx)
  1 comentario
Juan Manuel Hussein Belda
Juan Manuel Hussein Belda el 15 de Oct. de 2021
Thank you so much for the reply!! However, I think I tried to simplify the question and ended up asking it wrong. I will ask again, and sorry for the inconvenience!!
I have two vectors, see:
result = [7,5,6,4,0];
v_sample = [1,3,4,0,0];
v_real = [1,2,3,4,5];
What I would like is to obtain the following:
v_sample_new = [1, NaN, 3, 4, Nan]
result_new = [7, NaN, 5, 6, NaN]
So, basically, v_sample_new is ordered with respect to v_real, and result has the correspondant values ( result(i) is related to v_sample(i) ) in a manner that is consistent as shown. I do noy know if I have explained it properly but I hope so, and thank you so much again!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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