Aam*_*mir 20 matlab plot vector
我想知道在MATLAB中绘制矢量的最简单方法.例如:
a = [2 3 5];
b = [1 1 0];
c = a + b;
Run Code Online (Sandbox Code Playgroud)
我想将这个矢量加法可视化为头对尾/平行四边形方法.如何用箭头绘制这些矢量?
Amr*_*mro 25
a = [2 3 5];
b = [1 1 0];
c = a+b;
starts = zeros(3,3);
ends = [a;b;c];
quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3))
axis equal
Run Code Online (Sandbox Code Playgroud)
gno*_*ice 16
我同意Aamir的意见,Erik Johnson在MathWorks文件交换中提交的arrow.m是一个非常好的选择.您可以使用它来说明向量添加的不同方法,如下所示:
提示到尾方法:
o = [0 0 0]; %# Origin
a = [2 3 5]; %# Vector 1
b = [1 1 0]; %# Vector 2
c = a+b; %# Resultant
arrowStarts = [o; a; o]; %# Starting points for arrows
arrowEnds = [a; c; c]; %# Ending points for arrows
arrow(arrowStarts,arrowEnds); %# Plot arrows
Run Code Online (Sandbox Code Playgroud)平行四边形法:
o = [0 0 0]; %# Origin
a = [2 3 5]; %# Vector 1
b = [1 1 0]; %# Vector 2
c = a+b; %# Resultant
arrowStarts = [o; o; o]; %# Starting points for arrows
arrowEnds = [a; b; c]; %# Ending points for arrows
arrow(arrowStarts,arrowEnds); %# Plot arrows
hold on;
lineX = [a(1) b(1); c(1) c(1)]; %# X data for lines
lineY = [a(2) b(2); c(2) c(2)]; %# Y data for lines
lineZ = [a(3) b(3); c(3) c(3)]; %# Z data for lines
line(lineX,lineY,lineZ,'Color','k','LineStyle',':'); %# Plot lines
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
144175 次 |
| 最近记录: |