필터 지우기
필터 지우기

New matrix with only the negative numbers of another one

조회 수: 2 (최근 30일)
Ifigenia Aslanidou
Ifigenia Aslanidou 2021년 9월 10일
댓글: Ifigenia Aslanidou 2021년 9월 12일
Hello everyone,
say I have a matrix with positive and negative numbers,e.g A= [-1 ; -2 ; 6 ; -4 ; 5 ; 10; -22; 4];
How do I create a new matrix with only the positive/negative numbers of the matrix above? e.g A_neg=[-1;-2;-4;-22];
I know that with the find command I can find in which row/column these are, but I am not sure how to create another one.
Thanks in advance!
Greetings

채택된 답변

DGM
DGM 2021년 9월 10일
A = [-1 ; -2 ; 6 ; -4 ; 5 ; 10; -22; 4];
B = A(A<0)
B = 4×1
-1 -2 -4 -22

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by