negative positive sign matrix B need to follow matrix A

2 ビュー (過去 30 日間)
Noriham B
Noriham B 2022 年 9 月 15 日
コメント済み: Rik 2022 年 9 月 16 日
Dear all experts.
After all I got A=[ -1 3 -2 4 6]. For A, the value is not important. But the negative or positive sign is very important here. And also I have B=[2.1 2.2 4.2 4.5 5.8], the value of B are all positive . B value is very important because I need to get the sum of B. But before that, B need to follow negative sign as A. Therefore B become B=[-2.1 2.2 -4.2 4.5 5.8] before I want to sum it up. Really need help from all experts. Thank you in advance.

採用された回答

Rik
Rik 2022 年 9 月 15 日
The sign function seems an obvious choice:
A=[ -1 3 -2 4 6];
B=[2.1 2.2 4.2 4.5 5.8];
C=sign(A).*B
C = 1×5
-2.1000 2.2000 -4.2000 4.5000 5.8000
sum(C)
ans = 6.2000
  2 件のコメント
Noriham B
Noriham B 2022 年 9 月 16 日
thank you so much sir. May God bless you. Its really work.
Rik
Rik 2022 年 9 月 16 日
You're welcome

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by