Convert Nan to zero in fplot

3 ビュー (過去 30 日間)
Spencer Ferguson
Spencer Ferguson 2021 年 5 月 21 日
編集済み: Jaya 2021 年 5 月 22 日
Is there a way to convert any not a number values that arise in fplot to zero within the fplot function?
Within the error calculation below I get (0-0)/0 at the beginning of the interval, but I'm looking to plot it as zero (since it's zero error).
fplot((((f_disp-u_AB)/u_AB)*100),[0,100],'LineWidth',2,'color','green');
Thanks!

回答 (2 件)

Jaya
Jaya 2021 年 5 月 22 日
編集済み: Jaya 2021 年 5 月 22 日
You can do something like below example to make whatever NaN present in your (((f_disp-u_AB)/u_AB)*100) as 0. The A below can be your (((f_disp-u_AB)/u_AB)*100).
A = 0./[-2 -1 0 1 2] % gives 0 0 NaN 0 0
A(isnan(A))=0; % gives 0 0 0 0 0
Will work directly for matrix too.

Star Strider
Star Strider 2021 年 5 月 22 日
To plot the first value as 0, the most effective and efficient way to do what you want is to add a very small value (such as eps) to the denominator —
syms u_AB
f_disp = 0;
fplot((((f_disp-u_AB)/(u_AB+eps))*100),[0,100],'LineWidth',2,'color','green')
grid
xlim([0 eps*100]) % Zoom To Show Detail (Delete Later)
The first value is now (0/eps = 0) rather than NaN.
.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by