Deleting rows with specific values within a matrix

1 Ansicht (letzte 30 Tage)
Lewis Abrams
Lewis Abrams am 6 Apr. 2021
Kommentiert: Matt J am 6 Mai 2021
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 Kommentare
Rena Berman
Rena Berman am 6 Mai 2021
(Answers Dev) Restored edit
Matt J
Matt J am 6 Mai 2021
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 6 Apr. 2021
Bearbeitet: Matt J am 6 Apr. 2021
Hint: do something with this line:
ind = any( A==0 | abs(A)==10 ,2)
  2 Kommentare
Lewis Abrams
Lewis Abrams am 6 Apr. 2021
Bearbeitet: Rena Berman am 6 Mai 2021
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.
Matt J
Matt J am 6 Apr. 2021
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by