フィルターのクリア

fplot - vectorisation with inequalities

1 回表示 (過去 30 日間)
Vect13
Vect13 2019 年 7 月 2 日
回答済み: Star Strider 2019 年 7 月 2 日
Hi,
I am using fplot for the first time, and I am getting the message: Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
After some researches, I found out that fplot requires that I vectorise my code. So I switched / by ./ . However I have some if, elseif, else with inequalities as conditions.
function [phio] = phi_i(x,xi,i)
N=size(x,1)-1;
if i==1
if (xi(1)<=x && x<=xi(2))
phio=(xi(2)-x)./(xi(2)-xi(1));
else
phio=0;
end
elseif i==N+1
if (xi(N)<=x && x<=xi(N+1))
phio=(x-xi(N))./(xi(N+1)-xi(N));
else
phio=0;
end
else
if (xi(i-1)<=x && x<xi(i))
phio=(x-xi(i-1))./(xi(i)-xi(i-1));
elseif (xi(i)<=x && x<=xi(i+1))
phio=(xi(i+1)-x)./(xi(i+1)-xi(i));
else
phio=0;
end
end
end
I am using it such that
xi=0:0.5:10;
phii=@(x)phi_i(x,xi,6);
fplot(@(x)phii(x),[0 10],'b')
I guess that all the inequalities such as xi(i-1)<=x are a problem, if xi(i-1) is a scalar and x a vector, isn't it?
How could I remedy that? Thanks
Alex

回答 (1 件)

Star Strider
Star Strider 2019 年 7 月 2 日
The fplot function may be a bit sensitive with respect ot the functions you give it. Your code runs without error (only the warnings), so just ignore them.

カテゴリ

Help Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by