Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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);

Réponse acceptée

Stefan Raab
Stefan Raab le 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 commentaire
William Warren
William Warren le 26 Oct 2015
Modifié(e) : William Warren le 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])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by