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 :)

 채택된 답변

José-Luis
José-Luis 2013년 1월 8일
편집: José-Luis 2013년 1월 8일

1 개 추천

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

Bran
Bran 2013년 1월 8일
Hi there,
I'm so sorry Jose... I didn't realise that that is what I should do! Please accept my sincerest apologies! Many thanks for flagging this up to me! Serves my right for not reading the rules!
Happy New year! :) Bran
José-Luis
José-Luis 2013년 1월 8일
No worries, and no apologies needed. It's not really a rule, but something nice to do for the contributors. Anyway...
Cheers!
Bran
Bran 2013년 1월 10일
Hi there,
Just a quick question. I have applied this code to another matrix modifying it slightly to read;
your_mat = B2(all((-8/3)<=B2<=(8/3),2),:)because I want to keep all rows where the all the column numbers are greater than -8/3 or less than 8/3 however, the matrix I get is the exact same size as the original B2 and I know that this is not the case. Any ideas what could be going wrong??
Many thanks in advance :) Bran
José-Luis
José-Luis 2013년 1월 10일
편집: José-Luis 2013년 1월 10일
(-8/3)<=B2<=(8/3)
is not valid Matlab syntax. You could try instead:
abs(B2) <= 8/3
Bran
Bran 2013년 1월 14일
Many thanks, that worked for me :)

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Thomas
Thomas 2013년 1월 8일
편집: Thomas 2013년 1월 8일

0 개 추천

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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 8일
편집: Azzi Abdelmalek 2013년 1월 8일

0 개 추천

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)
nabin
nabin 2014년 5월 8일

0 개 추천

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]

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2013년 1월 8일

답변:

2014년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by