MATLAB'使用图向量的错误必须具有相同的长度.' [英] MATLAB 'Error using plot Vectors must be the same length.'
本文介绍了MATLAB'使用图向量的错误必须具有相同的长度.'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
x = 0:1:5; % define x array
y = exp(x)+x.^4+2*x.^2-x+3; % define y array
dx = diff(x); % 1 1 1 1 1 dx has one number less than x
dy = diff(y); % -5 -1 -3 -4 -2
slope = dy./dx
z=exp(x)+4*x.^3 +4*x-1
plot(x,slope,'*',x,z)
使用绘图向量的错误必须具有相同的长度."
'Error using plot Vectors must be the same length.'
由于坚持了一段时间,我不确定该怎么办.香港专业教育学院看到相同的错误的其他响应,但无法理解代码.似乎是冒号:可能有帮助,但我不确定如何使用它.
Been stuck on this for a while, I am not sure what to do. ive seen the other responses to the same error but can not understand the code. It seems its the colon : that might help but i am not sure how to use it.
任何帮助将不胜感激!
Any help would be appreciated!
推荐答案
由于slope
是根据两个连续值计算得出的,因此我建议您将连续点之间的平均值作为x
-倾斜的轴值:
Since slope
is computed from two consecutive values, I suggest you take the average betwen consecutive points as the x
-axis values for ´slope`:
plot((x(1:end-1)+x(2:end))/2,slope, '*',x,z)
这篇关于MATLAB'使用图向量的错误必须具有相同的长度.'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文