Filter löschen
Filter löschen

find a value and following values in a matrix

1 Ansicht (letzte 30 Tage)
elisa ewin
elisa ewin am 9 Sep. 2016
Beantwortet: Andrei Bobrov am 9 Sep. 2016
Hi, I have a matrix
A= [23 34 45 0 0 0; 21 34 0 0 23 11; 34 23 0 0 0 22]
I want to find if a value is present and if it's present, I want to find the following values.
Eg I want to find in A the value 23, if it's present I want like output a matrix only with 23 and its following values
B= [23 34 45 0 0 0; 0 0 0 0 23 11; 0 23 0 0 0 22]
Can you help me? thanks

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 9 Sep. 2016
out = (cumsum(A == 23,2)>0).*A

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by