我在尝试根据一个变量制作函数的2D图时遇到了一些麻烦。长话短说,这个功能只能接受标量值;它不接受矢量。因此,对于一系列独立值plot(vector, function(vector))
,不可能使用vector
。我也尝试过使用循环,但我的知识有限,而且无论如何都没有用。
总结一下:我想绘制function(x)
vs x
,但function
可能只有一个标量输入,所以取x=-10:1:10
然后将其绘制为{{1}不行。
任何人都能指出我正确的方向吗?
答案 0 :(得分:-1)
vector = -10:10 % set up your vector
output = zeros(size(vector); % initialise the output
for ii = 1:numel(vector)% loop over all elements of your vector
output(ii) = function(vector(ii)); % feed the function a single element at a time
end
plot(vector,output) % Now you can plot the two vectors