MATLAB Answers

take values from old matrix to newer

2 views (last 30 days)
tal shmuel
tal shmuel on 18 Jan 2020
Commented: Star Strider on 18 Jan 2020
hello
i got from a code matrix A in size 28281X5.
at colums 3, 4 and 5 there are negetive varibles.
i want to creat a new matrix from A matrix that include all the lines from A matrix withuot the lines with the
negative varibles
thanks for the help !
Tal

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 Jan 2020
Create the output matrix ‘B’ as:
B = A(all(A(:,3:5) >= 0, 2),:) % Result
Example—
A = [randi(9, 15, 2) randi([-4 +5], 15, 3)] % Create ‘A’
B = A(all(A(:,3:5) >= 0, 2),:) % Result

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 18 Jan 2020
That is an argument to the all function:
all(A(:,3:5) >= 0, 2)
It tells all to calculate the logic across columns (that is, across each row, dimension 2) rather than down the columns (that would be dimension 1). These are MATLAB dimension conventions for 2D arrays.
Star Strider
Star Strider on 18 Jan 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags

Products


Release

R2018b

Translated by