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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by