필터 지우기
필터 지우기

How to assign the value of the index to the index position?

조회 수: 5 (최근 30일)
Paul Hinze
Paul Hinze 2021년 12월 6일
댓글: KSSV 2021년 12월 6일
Hello dear Matlab Community
I have a row vector with the size of 1x40000. The vector consists of zeros and ones.
How can i convert the value ones to the value of their corresponding indices?
Here is a small example
v = [0 0 0 1 1 1 0 0 0]; % This vector ones at positions 4,5, and 6, and I want that the ones get changed by the values 4,5, and 6.
Thank you in advance,
Paul

채택된 답변

KSSV
KSSV 2021년 12월 6일
편집: KSSV 2021년 12월 6일
v = [0 0 0 1 1 1 0 0 0];
idx = find(v)
idx = 1×3
4 5 6
v(v==1) = find(v)
v = 1×9
0 0 0 4 5 6 0 0 0
  댓글 수: 2
Paul Hinze
Paul Hinze 2021년 12월 6일
Perfect, thank you
KSSV
KSSV 2021년 12월 6일
Thanks is accepting the answer .. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by