Error using plotv "too many input arguments"

I'm trying to generate a plot using these inputs:
% Particle 1
m1 = 1;
V1 = [2*cosd(45); -2*sind(45)];
% Particle 2
m2 = 2;
V2 = [cosd(45); sind(45)];
% Conservation of momentum and kinetic energy
Vcm = (m1*V1+m2*V2)/(m1+m2);
Vr = V1-V2;
Vrmag = norm(Vr);
Vr_starmag = Vrmag;
x = 0:30:360;
Vr_star = [Vrmag*sind(x); Vrmag*cosd(x)];
%% Outgoing velocity vectors
V1_star = Vcm+(m2/(m1+m2))*Vr_star;
V2_star = Vcm-(m1/(m1+m2))*Vr_star;
figure(1)
plot(V1,'r')
hold on
plot(V2,'b')
plotv(V1_star,'Color',[245/255 121/255 12/255])
plotv(V2_star,'g')
hold off
title('Collision results')
legend('C1','C2','C1^*','C2^*')
xlabel('X')
ylabel('Y')
V1_star and V2_star are both 2x13 matrices while V1 and V2 are both 2x1.
I need orange lines for V1_star so I used the rgb triplet code for orange. When I do this, I get the "too many input arguments". Is there better syntax for this or does plotv not recognize the rgb code? Thanks
Note:
plotv(V2_star,'g')
Returns the correct graph. Therefore it must be a formatting issue.

 Accepted Answer

The function plotv does not support the input argument 'Color'.
You could set the colororder property of the axis before plotting the orange lines.
colororder(gca,[245/255 121/255 12/255]);
plotv(V1_star)

4 Comments

This worked thank you!
Another quick question: When I generate the plot, the legend is correct for C1 and C2 but for C1* and C2* the line color is orange for both (just on the legend, they are the correct colors on the plot). I want C1* to be orange and C2* to be green on the legend. Heres my code from above:
figure(1)
plotv(V1,'r')
hold on
plotv(V2,'b')
colororder(gca,[245/255 121/255 12/255]);
plotv(V1_star)
plotv(V2_star,'g')
hold off
title('Collision results')
legend('C1','C2','C1^*','C2^*')
xlabel('X')
ylabel('Y')
Anything you recommend?
The problem is each legend item aligns with a line on the plot, and you have 13 orange lines to get through before you get to the green lines. You can see this by turning on the plot browser in the Figure window's view menu.
The simplest way to correct for this is modify your plot order to first plot one of each line, then plot the remaining items
figure(1)
plotv(V1,'r')
hold on
plotv(V2,'b')
colororder(gca,[245/255 121/255 12/255]);
plotv(V1_star(:,1))
plotv(V2_star(:,1),'g')
colororder(gca,[245/255 121/255 12/255]);
plotv(V1_star(:,2:end))
plotv(V2_star(:,2:end),'g')
hold off
title('Collision results')
legend('C1','C2','C1^*','C2^*')
xlabel('X')
ylabel('Y')
Another way would be to rearrange the line order programmatically before adding the legend.
myLines = get(gca,'Children');
set(gca,'Children',myLines([1:12 14:25 13 26:28]));
legend('C1','C2','C1^*','C2^*')
Awesome thank you
Here's a simpler way!
figure(1)
C1=plotv(V1,'r')
hold on
C2=plotv(V2,'b')
colororder(gca,[245/255 121/255 12/255]);
C1star = plotv(V1_star)
C2star = plotv(V2_star,'g')
hold off
title('Collision results')
legend([C1 C2 C1star C2star],{'C1','C2','C1^*','C2^*'})
xlabel('X')
ylabel('Y')

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!