Selecting from a range of values from a column matrix

조회 수: 1(최근 30일)
I have a column matrix (398404 x1). I want any values less than 42 between rows 290360 and 380876 to be 5 while values outside those rows remain the same. Please I need help. Thank you.

채택된 답변

Walter Roberson
Walter Roberson 2021년 10월 7일
r1 = 290360; r2 = 380876;
extract = YourMatrix(r1:r2);
extract(extract < 42) = 5;
YourMatrix(r1:r2) = extract;
r1 = 290360; r2 = 380876;
rowidx = (1:numel(YourMatrix)).';
mask = rowidx >= r1 & rowidx <= r2 & YourMatrix < 42;
YourMatrix(mask) = 5;
  댓글 수: 1
Austin Ukpebor
Austin Ukpebor 2021년 10월 7일
It works! Apart from array indexing, what other areas would you recommend I read up?
Thank you.

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

추가 답변(0개)


Find more on Creating and Concatenating Matrices in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by