MATLAB Answers

Storing indices from a matrix

6 views (last 30 days)
Hye all. I am relatively new with Matlab. I am modelling a vehicle suspension system right now.
Assume I have a column matrix that has 6 elements. A= [ 1 2 3 -4 6 -2]'
I want to extract the index of the values that are negative, and store all of them as a column matrix or an array 'B'.
Expected result : B= [4 6]
Kindly help.

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 2 Mar 2020
Edited: Stephan on 2 Mar 2020
A= [ 1 2 3 -4 6 -2]'
B = find(A<0)
A =
1
2
3
-4
6
-2
B =
4
6

  1 Comment

shahzer rahman
shahzer rahman on 2 Mar 2020
Thanks man. works fine.

Sign in to comment.

More Answers (0)