Effacer les filtres
Effacer les filtres

Creating a submatrix from a matrix

6 vues (au cours des 30 derniers jours)
Bran
Bran le 8 Jan 2013
I have a matrix for example; A = {1 3 7; 10 1 2; 11 5 9; 12 2 5] (however, mine is much bigger) And I would like to keep the rows where all the elements in the row are less than or equal to 7 to put into a new submatrix called B. How would I go about this?
Many thanks for any help you can give :)

Réponse acceptée

José-Luis
José-Luis le 8 Jan 2013
Modifié(e) : José-Luis le 8 Jan 2013
A = [1 3 7; 10 1 2; 11 5 9; 12 2 5]
your_mat = A(all(A<=7,2),:);
I looked at your question history. Please accept an answer if it helped you. It is the only "payment" contributors in this forum receive.
  5 commentaires
José-Luis
José-Luis le 10 Jan 2013
Modifié(e) : José-Luis le 10 Jan 2013
(-8/3)<=B2<=(8/3)
is not valid Matlab syntax. You could try instead:
abs(B2) <= 8/3
Bran
Bran le 14 Jan 2013
Many thanks, that worked for me :)

Connectez-vous pour commenter.

Plus de réponses (3)

Thomas
Thomas le 8 Jan 2013
Modifié(e) : Thomas le 8 Jan 2013
A = [1 3 7; 10 1 2; 11 5 9; 12 2 5]
out=A(find(sum(A<=7,2)==size(A,2)),:) % rows with elements <=7
  1 commentaire
Bran
Bran le 8 Jan 2013
Thanks Guys for all the help!

Connectez-vous pour commenter.


Azzi Abdelmalek
Azzi Abdelmalek le 8 Jan 2013
Modifié(e) : Azzi Abdelmalek le 8 Jan 2013
A = {1 3 7; 10 1 2; 11 5 9; 12 2 5};
B=cell2mat(A);
out1=B(B<7);
n=numel(out1);
n1=floor(sqrt(n));
m1=ceil(n/n1);
out=cell(1,n1*m1);
out(1:n)=num2cell(out1)';
B=reshape(out,n1,m1)
  1 commentaire
Bran
Bran le 8 Jan 2013
Many thanks for the help!

Connectez-vous pour commenter.


nabin
nabin le 8 Mai 2014
I have a matrix A=[1 2 3; 1 2 9; 2 3 4]. I want a matrix B whose column 1 is equal to 1. How can I do this? B=[1 2 3; 1 2 9]

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by