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

10 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Stefan Raab
Stefan Raab il 26 Ott 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 Commento
William Warren
William Warren il 26 Ott 2015
Modificato: William Warren il 26 Ott 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])

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Schedule Model Components in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by