How to make 2 matrix out of 1 one matrix??

조회 수: 4 (최근 30일)
Ali nouri
Ali nouri 2020년 6월 25일
댓글: Alan Stevens 2020년 6월 26일
Hi Guys,
I have a 8760X30 matrix, which is included with the positive and negative number. Now I want to make 2 matrix of the originally matrix with the same dimension.
The difference is in one matrix should included the possitive number from the originally matrix and replace the negatives with zero, and in the other matrix should included with negative value and replace positive number with zero.
How can I do it?

채택된 답변

Alan Stevens
Alan Stevens 2020년 6월 25일
If your first matrix is A, then:
ix = find(A>0); B = A; B(ix) = 0;
ix = find(A<0); C = A; C(ix) = 0;
  댓글 수: 2
Sugar Daddy
Sugar Daddy 2020년 6월 26일
using find is inefficient in such kind of scenaria.
Alan Stevens
Alan Stevens 2020년 6월 26일
I agree that the "find" version is not the most efficient. However, sometimes clarity is more important than efficiency, and I suggest that, for a novice, the "find" version is clearer.

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

추가 답변 (1개)

Sugar Daddy
Sugar Daddy 2020년 6월 25일
편집: madhan ravi 2020년 6월 26일
Aneg = (A<0) .* A
Apos = (A>0) .* A

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by