How to change index value of logical array.

조회 수: 21 (최근 30일)
Stephen john
Stephen john 2022년 8월 4일
댓글: Walter Roberson 2022년 8월 4일
Hello everyone i hope you are doing well. I have the following logical array in which some values are 1 for example
the value for index 13 to 17 are 1.
  • first i want to find where 1 values exist.
  • then find minimum and maximum value where 1 exist.
  • Then I want to change minimum and maximum index for example if 1 exist in 13 index the 50 were added to it and new index is 63 and new index for 17 is 67.
now the minimum value is 63 and maximum value is 67 where 1 value exist.
How can i do it in MATLAB

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 4일
locs = find(Mask);
first = locs(1);
last = locs(end);
With regards to changing the index: what do you want to do if there are 1s within the last 50 entries? Do you want to put 50 0's at the beginning, making the whole thing 50 longer? Do you want to shift by 50 but the array should stay the same length provided that no 1s were moved outside of the original length? But if some 1s got moved outside the original length should the array become longer but ending at the last 1?
  댓글 수: 4
Stephen john
Stephen john 2022년 8월 4일
@walter Can you please share the modified code?
Walter Roberson
Walter Roberson 2022년 8월 4일
idx = find(mask);
row1 = min(idx);
row2 = max(idx);
shifted_mask = circshift(mask, 50);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by