creating line plot with different marker color and legends

7 views (last 30 days)
Hi,
I have data stored in two arrays as follows.
A = [10.15 , 10.92, 11.81,12.83]
B = [3.92, 9.18, 14.87, 18.14].
I am creating plot using the below shown script. Here, I would like to create line plot with different marker colors and also the legends. I can able to generate different marker color and legends, but not with the line. Is there any way to create line plot with this ??
plot (A (1,1), B(1,1), '*','color', 'b','markersize',20);
hold on
plot (A (2,1), B(2,1), '*','color', 'r','markersize',20);
hold on
plot (A (3,1), B(3,1), '*','color', 'g','markersize',20);
hold on
plot (A (4,1), B(4,1), '*','color', 'm','markersize',20);
hold on
set (gca, 'Linewidth', 2);
set(gca, 'FontSize', 18)
set(gca,'TickLabelInterpreter','latex')
legend({'$\alpha_{a}=0$','$\alpha_{b}=0.1$','$\alpha_{c}=0.2$','$\alpha_{d}=0.3$'},'Interpreter','latex');

Accepted Answer

Cris LaPierre
Cris LaPierre on 18 Sep 2021
Your data is a row vector (1xn) but you are indexing it like it is a column vector (mx1). Since it is a vector, perhaps it is best to just use a single index to avoid this issue.
A = [10.15 , 10.92, 11.81,12.83];
B = [3.92, 9.18, 14.87, 18.14];
plot (A(1), B(1), '*','color', 'b','markersize',20);
hold on
plot (A(2), B(2), '*','color', 'r','markersize',20);
plot (A(3), B(3), '*','color', 'g','markersize',20);
plot (A(4), B(4), '*','color', 'm','markersize',20);
hold off
set(gca, 'Linewidth', 2,'FontSize', 18,'TickLabelInterpreter','latex')
legend({'$\alpha_{a}=0$','$\alpha_{b}=0.1$','$\alpha_{c}=0.2$','$\alpha_{d}=0.3$'},'Interpreter','latex');
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!