Effacer les filtres
Effacer les filtres

How to remove certain rows and columns in a matrix?

1 vue (au cours des 30 derniers jours)
Ali
Ali le 10 Juil 2020
Commenté : Ali le 10 Juil 2020
I have this 8x8 matrix and I want to preserve only the 1, 2, 7 and 8 (for now, these numbers change based on a computation) rows and column to get a 4x4 output matrix. How can I delete other columns and rows or copy the forementioned rows and columns to a new matrix with a new 4x4 structure?
Keep in mind that the desired rows and columns change based on a function computation.
A = [
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0 ]
Desired output (for this context):
A = [
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0 ]
  2 commentaires
Stephen23
Stephen23 le 10 Juil 2020
>> B = A([1,2,7,8],[1,2,7,8])
B =
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
Ali
Ali le 10 Juil 2020
Thanks @Stephen, nice and clean solution. ;)

Connectez-vous pour commenter.

Réponse acceptée

madhan ravi
madhan ravi le 10 Juil 2020
Modifié(e) : madhan ravi le 10 Juil 2020
w = A([1,2,7,8], :)
Wanted = w(:, [1,2,7,8])
  1 commentaire
Ali
Ali le 10 Juil 2020
Modifié(e) : Ali le 10 Juil 2020
You're a lifesaver buddy! Respect! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by