How to add a number to the negative values in a vector?

2 ビュー (過去 30 日間)
Meshooo
Meshooo 2014 年 2 月 26 日
コメント済み: Lyndon Nawanao 2022 年 2 月 4 日
Dear All,
I have a vector [A] which includes positive and negative values A = [1 4 5 2 -3 4 5 7 -6 -6]. I want to change those negative values by adding -180 to them, so my new vector will be like this
A = [1 4 5 2 -183 4 5 7 -186 -186].
Any idea how find that?
So far I tried this but not working
for i = 1:10
for j = 1:1
if A(i,j)<=0
A(i,j) = A + -180;
end
end
end

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 2 月 26 日
編集済み: Andrei Bobrov 2014 年 2 月 26 日
A = [1 4 5 2 -3 4 5 7 -6 -6];
t = A < 0;
A(t) = A(t) - 180;
ADD
May be use the following:
A = mod(A,180);
I think that '180' it 'pi' in this case.
  2 件のコメント
Meshooo
Meshooo 2014 年 2 月 26 日
It works! thank you very much..
Lyndon Nawanao
Lyndon Nawanao 2022 年 2 月 4 日
Hi Andrei. Thank you for this! I would like to ask what syntax is this in matlab? Apparently, the if statements (if A<0 A=A-180)did not work but this one did. Thanks in advance.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by