Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

KSSV
KSSV il 15 Ott 2021
v = [1,2,3,4,5];
idx = 3;
iwant = NaN(size(v)) ;
iwant(idx) = v(idx)
  1 Commento
Juan Manuel Hussein Belda
Juan Manuel Hussein Belda il 15 Ott 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!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by