我在编写此代码时遇到问题。所以,我正在尝试为
制作代码func = y * x(n)+ z * x(n)
所有值都是任意值,x(n)是位置n处的值。我需要在每个第n个位置绘制一个图形。因此,如果x(1)= 5,我在x = 1和y = 5时绘制一个点。问题是,当我在第n个位置添加x(n)值时,我无法弄清楚如何制作任意数组并且不知道如何获得func的答案。我也无法绘制图表,但认为这是因为我无法弄清楚使用该数组。
我是MatLab的新手。
答案 0 :(得分:0)
所以,如果我关注y& z只是常数?我认为混淆通常会写成“y = a x + b x”
像上面评论中提到的Cris Luengo一样,你应该阅读一些基本的Matlab教程,因为这是非常基础的。% y and Z are constants
y = 1;
z = 2;
%this makes x = [0,1,2,...10];
x = 0:1:10;
func = y.*x + z.*x;
plot(func)
答案 1 :(得分:0)
这应该可以解决问题:
% Define X as a range between -10 to 10 (+1 on every step)...
x = -10:10;
% Define your constants...
y = 3;
z = -1;
% Define the function...
fun = @(x) (y .* x) + (z .* x);
% Plot X on the x-axis and fun(x) on the y-axis...
% fun(x) numerically evaluates fun for the given x
plot(x,fun(x));
有关匿名函数的详细信息,请参阅this page。