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

2 ビュー (過去 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
  1 件のコメント
Sugar Daddy
Sugar Daddy 2020 年 6 月 26 日
beauty madhan

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by