フィルターのクリア

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

1 回表示 (過去 30 日間)
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?

採用された回答

KSSV
KSSV 2021 年 10 月 15 日
v = [1,2,3,4,5];
idx = 3;
iwant = NaN(size(v)) ;
iwant(idx) = v(idx)
  1 件のコメント
Juan Manuel Hussein Belda
Juan Manuel Hussein Belda 2021 年 10 月 15 日
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!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by