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

8 views (last 30 days)
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);

Accepted Answer

Stefan Raab
Stefan Raab on 26 Oct 2015
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 Comment
William Warren
William Warren on 26 Oct 2015
Edited: William Warren on 26 Oct 2015
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])

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!