![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188438/image.jpeg)
Plotting 2D graph problem with x-axis spacing.
1 次查看(过去 30 天)
显示 更早的评论
I want to plot y = 2*exp((t.^2/)2) in MATLAB in the range of 0 to 3. I can't seem to get the vector length correctly and getting:
error using plot. Vectros must be the same length.
I understand that the vectors need to be the same length, but cannot actually implement this.
Code:
x = 0:0.1:3;
y = 2*(exp((t.^(2))/2));
plot (x,y,'r');
Without the 'x variable, the plot comes to:
plot (y,'r');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171338/image.png)
Comparing this to an online plotting tool for
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171339/image.png)
gives:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171340/image.png)
Which does not seem to be exactly what I am getting as a result in MATLAB.
- Is the equation for plotting written correctly?
- How do I get the x-axis to range from 0 to 3?
Many thanks for any suggestions.
2 个评论
KALYAN ACHARJYA
2018-3-17
编辑:KALYAN ACHARJYA
2018-3-17
From the above expression, x is independent with y. And what about the x range. Clarify "A Spacing" means?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188438/image.jpeg)
采纳的回答
KALYAN ACHARJYA
2018-3-17
编辑:KALYAN ACHARJYA
2018-3-17
%Note: range t from - to +
t=-2:0.1:2;
%x=-3:0.1:3;
y=2.*(exp((t.^(2))/2));
plot(t,y,'linewidth',3);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180153/image.jpeg)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!