How to remove position that is not in conditions from a matrix?
1 view (last 30 days)
Show older comments
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 .
0 Comments
Answers (1)
Image Analyst
on 18 May 2022
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.
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!