fplot - vectorisation with inequalities

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Measurements 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