How do i plot multiple vectors tip to tail, beginning from the origin?

2 ビュー (過去 30 日間)
William Warren
William Warren 2015 年 10 月 26 日
編集済み: William Warren 2015 年 10 月 26 日
This is my code thus far, but my figure only runs the plot for the variables as they are. I need them to run sequentially, so that they are connected tip to tail, forming one line that begins at the origin.
vectors = xlsread('Book1.xlsx'); %Enter any .xlsx document here
[M,N] = size(vectors);
hold on
x = (vectors(:,1).*cosd(vectors(:,2)));
y = (vectors(:,1).*sind(vectors(:,2)));
plot(x,y);

採用された回答

Stefan Raab
Stefan Raab 2015 年 10 月 26 日
x = (vectors(:,1).*cosd(vectors(:,2)));
y = (vectors(:,1).*sind(vectors(:,2)));
plot([0; x; 0],[0; y; 0]);
Is this what you need?
  1 件のコメント
William Warren
William Warren 2015 年 10 月 26 日
編集済み: William Warren 2015 年 10 月 26 日
No, not quite. I actually got something that came out more like this...it has some bugs that I could use some help identifying.
vectors = xlsread('Book2.xlsx'); %Enter any .xlsx document here
[M,N] = size(vectors); %vectors = [4,41;12,52;3,73;5,37;6,45]
xval = zeros(length(vectors),1);
yval = zeros(length(vectors),1);
xi = 0;
yi = 0;
xf = 0;
yf = 0;
hold on
for i = 1:length(vectors)
xcomp = (vectors(i,1).*cosd(vectors(i,2)));
ycomp = (vectors(i,1).*sind(vectors(i,2)));
xf = xcomp + xf;
yf = ycomp + yf;
x = [xi,xf];
y = [yi,yf];
plot(x,y,'k');
xi = xf;
yi = yf;
end
endx = [xf,0];
endy = [yf,0];
plot(endx,endy,'r')
hold off
xlabel('Force in X-Direction')
ylabel('Force in the Y-Direction')
axis ([0,inf,0,inf])

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by