Plot eigen Vector e1 & e2 in matlab?

5 ビュー (過去 30 日間)
Tanya
Tanya 2014 年 2 月 18 日
回答済み: jandas 2014 年 2 月 19 日
How to be able plot eigen vector in Matlab an make it sure have the exact position as a new axes of our data??
here is my code for PCA
a= randn(100,3);
b=mean(a);
c=cov(a);
[vec,val] = eigs(c);
e1=vec(:,1);
e2=vec(:,2);
plot3(a(:,1),a(:,2),a(:,3),'ro');
hold on
%%Here is the Problem begins
plot(e1,'k--');
plot(e2,'k--');
Here is the output that I got
That two lines represent the e1&e2 .
How to plot the e1 & e2 properly in 3D Vectors (plot3)???

回答 (1 件)

jandas
jandas 2014 年 2 月 19 日
The problem is that you try to plot the vector using 2D line plot so your script actually plots two lines in the XY plane through points {1, e1(1)}, {2, e1(2)}, {3, e1(3)} and {1, e2(1)}, {2, e2(2)}, {3, e2(3)}. If you need to plot a 3D vector you can plot it as a line between two points, e.g.:
plot3([0; e1(1)], [0; e1(2)], [0; e1(3)], 'k--');
plot3([0; e2(1)], [0; e2(2)], [0; e2(3)], 'k--');

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by