Deleting rows with specific values within a matrix

Here is the given question:
Create a matrix, A, of dimension of random integers in the range . Now create a new matrix from A by removing any rows that contains either -10, 0, 10.
I have create the random matrix
A = randi([-10, 10], [7,12])
Despite looking online, I am yet to find anything similar.
Thanks for the help.

4 Comments

This sounds like a homework question. Then please post, what you have tried so far and ask a specific question. It is not useful, if the forum solves your homework.
I do mention it is a given question.
I am not asking for it to be solved, I would like to know how to work it out. Any ideas on what to use or how to think about it would be useful.
As Matt has done to help.
(Answers Dev) Restored edit
A record of the original question:
Here is the given question:
Create a matrix, A, of dimension of random integers in the range . Now create a new matrix from A by removing any rows that contains either -10, 0, 10.
I have create the random matrix
A = randi([-10, 10], [7,12])
Despite looking online, I am yet to find anything similar.
Thanks for the help.

Sign in to comment.

Answers (1)

Hint: do something with this line:
ind = any( A==0 | abs(A)==10 ,2)

2 Comments

Thank you Matt, I am relatively new to the software.
What is the purporse of the ind and abs in this line. I have looked up their uses on the MATLAB help section but still need help understaning. I see that running this line allows me to see which rows have one of the factors, and which ones do not.
Using:
A = randi([-10,10], [7,12])
ind = any( A==0 | abs(A)==10 ,2)
out=A(ind,:)
I am able to remove the rows not containing the stated figures. Is there a way to reverse this>
Thanks again.
abs() is absolute value.
c=abs([-10, 10])
c = 1×2
10 10
The line I've shown you really is by far the hardest part. If you don't know what to do from here, I think you need to review the Matlab on-ramp material.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Asked:

on 6 Apr 2021

Commented:

on 6 May 2021

Community Treasure Hunt

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

Start Hunting!