フィルターのクリア

I have a matrix, I want all values inside the matrix greater than 2*pi to be subtracted by 2*pi. All values less than 0 to have 2*pi be added to them. Other terms stay constant.

1 回表示 (過去 30 日間)
I have a matrix, I want all values inside the matrix greater than 2*pi to be subtracted by 2*pi, all values less than 0 to have 2*pi be added to them. Other terms stay constant as they are.
I have tried code below, but it does nothing. (I tried to change the theta4 > 2pi, then theta4 = 0 and nothing happened to my graph, althought some values are clearly above 0)
Theta4 is my matrix "[1x111] double" with "random" numbers.
I am not an expert in matlab, and some explination would be great.
%{
if theta4 > 2*pi
theta4 = theta4 - 2*pi;
elseif theta4 < 0
theta4 = theta4 + 2*pi ;
else
theta4= theta4 ;
end
%}
  2 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 2 月 11 日
gabriel - suppose your matrix has 4*pi as one of its elements. If we subtract 2*pi, then we are left with 2*pi. Should we subtract 2*pi again (and continue to do so) until the result is less than 2*pi?
gabriel rios
gabriel rios 2019 年 2 月 11 日
Interesting thought experiment, but I think my attempted if statement would stop that
Just to complelety clarify, I want all my values inbeetween 0-2pi values. With my attemped solution
if theta > 2 pi , meaning not 2pi = 2pi but 2pi+0.01 > 2pi then it would subract 2pi
if theta < 0 then add to 2pi to make it positive, but less than 2pi
else if theta somehow ends up 2pi exact, end.
These are all numbers in a matrix (1x111 double). I am satisfied when all values inside are
0 <= x <= 2 pi . I attamped another if statement, and it did not change my matrix. If statement is NOT changing my matrix values.
if theta4 > 2*pi
theta4 = theta4 - 2*pi;
elseif theta4 < 0
theta4 = theta4 + 2*pi ;
elseif theta4==theta4
theta4 = theta4
else
theta4=0
end

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

採用された回答

John D'Errico
John D'Errico 2019 年 2 月 11 日
Theta4 = mod(Theta4,2*pi);
  1 件のコメント
gabriel rios
gabriel rios 2019 年 2 月 11 日
I do think this is, all values minized. I don't know how, but Ill take it!
Thanks sir

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by