"Undefined function or variable 'x'." for input of function
显示 更早的评论
I had a function which was working perfectly for a while, however suddenly stopped working. The function is to plot a 2D vector field with inputs of the components in the x-direction (i) and y-direction (j) as well as mins and maxes.
function [ output ] = VecField(i,j,min,max)
% SCRIPT FOR PLOTTING VECTOR FIELDS
% Use defined range to create matrix of x,y values.
[x,y] = meshgrid(min:20:max);
% Plot vectors
quiver(x,y,i,j,'color','red','linewidth',1.2)
% Define axes based on given range
if min > 0
min_axes = 0.95*min;
else
min_axes = 1.05*min;
end
if max > 0
max_axes = 1.05*max;
else
max_axes = 0.95*max;
end
% Graph configuration
axis([min_axes max_axes min_axes max_axes])
title('Velocity vector field plot of over cylinder (inviscid)')
xlabel('x-axis')
ylabel('y-axis')
end
An example input which was previously working is: VecField(((-x-y)./((x.^2+y.^2).^0.5)),((x-y)./((x.^2+y.^2).^0.5)),-200,200)
While I can understand the error (Undefined function or variable 'x'.), I am unsure how to remedy it. If I enclose the functions in quotation marks, then the quiver function can no longer handle the inputs.
Are there any simple ways of getting around this?
3 个评论
Curtnos
2016-5-21
dpb
2016-5-21
Amplifying Stephen's comment, I don't see anything wrong w/ x,_y_ in your function but from
help quiver
...
quiver(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
at the points (x,y). The matrices X,Y,U,V must all be the same size...
Your function creates a 2D grid for the positions, but passes in i and j which should be the velocity components. Looks peculiar; should they probably not also be output from meshgrid, perhaps???
Also, you have an [output] argument, but it is never defined???
Curtnos
2016-5-21
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
