Filter löschen
Filter löschen

fplot - vectorisation with inequalities

1 Ansicht (letzte 30 Tage)
Vect13
Vect13 am 2 Jul. 2019
Beantwortet: Star Strider am 2 Jul. 2019
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

Antworten (1)

Star Strider
Star Strider am 2 Jul. 2019
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.

Kategorien

Mehr zu Measurements and Feature Extraction finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by