1

I want to add some arrows (direction) to my plot like this picture:

enter image description here

I used Arrowhead and arrowPlot but I have some errors.

a1 = 1.05;
b = 0.29;  
c = 0.3;
d= 0.31;


L1= 0.002;
L2= 0.008;
L3=0.0075;
L4 =0.006;

M1 = 0.0023;
N1 = 0.0035;
P1 = 0.003;


eta = [60 30 30 30];
F = @(t,y) [
    a1*y(1) - L1*y(1)*y(1) - L2*y(1)*y(2) - L3*y(1)*y(3) - L4*y(1)*y(4);
    -b*y(2) + M1*y(2)*y(1);
    -c*y(3) + N1*y(3)*y(1);
    -d*y(4) + P1*y(4)*y(1)];
[t,y] = ode45(F,(0: (300/1000000): 300), eta);

plot(y(:,1),y(:,2)+y(:,3)+y(:,4), 'LineWidth',2)
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
MathMath
  • 57
  • 4

1 Answers1

0

You can use "annotation('arrow',x,y)" command. Below I added some arrows to your plot. You can add some more but only remember that X and Y values must be between 0 and 1.

f1=[0 0 1];%Arrow's Color (Blue)
a1 = 1.05;
b = 0.29;  
c = 0.3;
d= 0.31;


L1= 0.002;
L2= 0.008;
L3=0.0075;
L4 =0.006;

M1 = 0.0023;
N1 = 0.0035;
P1 = 0.003;


eta = [60 30 30 30];
F = @(t,y) [
    a1*y(1) - L1*y(1)*y(1) - L2*y(1)*y(2) - L3*y(1)*y(3) - L4*y(1)*y(4);
    -b*y(2) + M1*y(2)*y(1);
    -c*y(3) + N1*y(3)*y(1);
    -d*y(4) + P1*y(4)*y(1)];
[t,y] = ode45(F,(0: (300/1000000): 300), eta);

plot(y(:,1),y(:,2)+y(:,3)+y(:,4), 'LineWidth',2)
%Plotting Arrows%
annotation('arrow', [.56 .58], [.221 .223],'color',f1);%left to right arrow
annotation('arrow', [.35 .37], [.221 .223],'color',f1);% ///  ///
annotation('arrow', [.37 .35], [.701 .703],'color',f1); %right to left arrow
annotation('arrow', [.74 .72], [.701 .723],'color',f1);
  • Thank you. Can I use "annotation('arrow',x,y)" for a 3dim plot with plot3 by adding another axis like "annotation('arrow',x,y, z)"? – MathMath Sep 20 '21 at 14:05
  • As much as I know annotation only creates 2D arrows therefore you can not add a z dimension to it, but you can use the previous code in a 3D plot, it will plot a 2D arrow in a 3D figure. – photonics_student Sep 28 '21 at 11:06