フィルターのクリア

Where is the logic failure in my code ?

2 ビュー (過去 30 日間)
farzad
farzad 2019 年 12 月 27 日
回答済み: Image Analyst 2020 年 1 月 9 日
Hi All
I have a matrix n x 1 called X , in which I want to move it up or down along vertical axis when I plot it vs time , in a way to make the mean value = 0 if it's not so I created a true false parameter as :
useMean
than can be
True
or
False
and then in the code I do :
if useMean == 'True'
if meanX <0
X= X+abs(meanX);
else
X= X-abs(meanX);
end
elseif useMean == 'False'
X=X;
end
but I noticed the code only can perform when useMean == 'True' , not the 'False' !
this way my rest of the parameters can not be calculated
  4 件のコメント
farzad
farzad 2019 年 12 月 27 日
I got it , I didn't have to write 'True' but simply true, cause true gives logical value 1
Walter Roberson
Walter Roberson 2019 年 12 月 27 日
編集済み: Walter Roberson 2019 年 12 月 27 日
Your code can be shortened to
if useMean
X = X - meanX;
end
with no abs() needed.

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

採用された回答

Image Analyst
Image Analyst 2020 年 1 月 9 日
Use true or false, not 'True' or 'False'. No quotes or capitalization required.
Or don't even use them at all. Your code could be:
if useMean
if meanX <0
X= X+abs(meanX);
else
X= X-abs(meanX);
end
else
X=X; % Even this is not needed.
end
but best would be to use Walter's code in the last comment above.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by