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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by