フィルターのクリア

"I'm trying to add an 'if' statement to analyze each result, but Matlab is 'ignoring' the condition and not performing the addition."

1 回表示 (過去 30 日間)
"I'm trying to add an 'if' statement to analyze each result, but Matlab is 'ignoring' the condition and not performing the addition."
I need that when some value of c (not all) is less than 0, d becomes rad2deg(theta) + 180, when any of the values of c is greater than or equal to 0, d becomes rad2deg(theta)
"The values of c are attached."
I think I'm not managing to explain my problem, I'll try again:
theta = acos(UV ./ Uv);
c = Y(:,2); where Y(:,2) is generated by ode45, meaning there are several values (a total of 547).
I need to check the values of "c." When the value of "c" is < 0, the value of "d" is d = rad2deg(theta) + 180; when not, d = rad2deg(theta).
So, for each value analyzed in "c," a value of "d" is calculated (if <0, d = rad2deg(theta) + 180; if not, d = rad2deg(theta)), meaning, in the end, I will have 547 values of "d" based on the rules above.
Thank you very much for your attention.
[T,Y] = ode45(@myprog,tSpan,s,options);
.
.
.
c = Y(:,2);
if c < 0
d = rad2deg(theta) + 180;
else
d = rad2deg(tetha);
end
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 19 日
Is theta a scalar or a vector? Is it calculated from c? Is it possibly the same as c ?
Daniel santiago Umaña
Daniel santiago Umaña 2023 年 10 月 20 日
"The values of c are attached."
I need to take these values, and if they are less than 0, d = rad2deg(theta) + 180, if they are greater than zero, d = rad2deg(theta)

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

回答 (2 件)

the cyclist
the cyclist 2023 年 10 月 19 日
Is c a vector? If so, then all elements of c would have to be less than zero, to enter the if condition. This is explained in the documentation.
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 19 日
The second output of ode45 is guaranteed to have at least three rows (unless there are perhaps some strange combinations of circumstances.) Just maybe if there was an event function that always signalled termination you might be able to get it down to two rows.
Daniel santiago Umaña
Daniel santiago Umaña 2023 年 10 月 20 日
"The values of c are attached."
I need to take these values, and if they are less than 0, d = rad2deg(theta) + 180, if they are greater than zero, d = rad2deg(theta)

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


Torsten
Torsten 2023 年 10 月 19 日
移動済み: Torsten 2023 年 10 月 19 日
c is a vector. Do you want d to be rad2deg(theta) + 180 if all elements of the vector c are < 0 ? Then your code is correct. Otherwise you have to loop over the elements of c:
for i = 1:size(c,1)
if c(i) < 0
...
else
...
end
end
  10 件のコメント
Torsten
Torsten 2023 年 10 月 20 日
編集済み: Torsten 2023 年 10 月 20 日
We don't know the size of the array "theta", but most probably you mean
for i = 1:size(c,1)
if c(i) < 0
d(i) = rad2deg(theta(i)) + 180
else
d(i) = rad2deg(theta(i))
end
end
or shorter
d = rad2deg(theta);
d(c<0) = d(c<0) + 180;
Daniel santiago Umaña
Daniel santiago Umaña 2023 年 10 月 20 日
Thank you very much, this is exactly what I needed! Thanks!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by