How to remove position that is not in conditions from a matrix?

1 回表示 (過去 30 日間)
Real A
Real A 2022 年 5 月 18 日
回答済み: Image Analyst 2022 年 5 月 18 日
Hi, I have a small problem, I want remove the position that is not in conditions from a matrix.
For example, If i have A = [ 1 2 1 3 1 2 2 ] and cumsum them ---> B = [ 1 3 4 7 8 10 12 ]
and I want to remove the first position that B>5 or A(1,4) and rearrange to recalculate and repeat them
  • A = [ 1 2 1 1 2 2 ] ---> B = [ 1 3 4 5 7 9 ] ---> remove A(1,5)
  • A = [ 1 2 1 1 2 ] ---> B = [ 1 3 4 5 7 ] ---> remove A(1,5)
  • A = [ 1 2 1 1 ] ---> B = [ 1 3 4 5 ] ---> stop
Thank you for helping me .

回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 18 日
Using find() inside a while loop should allow you to finish this homework problem.
A=
B=
while max(B) > 5
index = find()
if ~isempty(index)
% Code
end
end
etc. I'm sure you can finish it.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by