Changing the marker type for the nth entry in plot

8 views (last 30 days)
I've been working on a project where we are changing 2 variables and the outputs are T values and Y values. Here's pretty much what the data looks like.
T1 = [1;3;5;7];
T2 = [0.9;2.7;5;6.8];
T3 = [1;2.9;5.1;7];
Y1 = [1;2;1;2];
Y2 = [4;5;6;4];
Y3 = [7;8;7;7];
figure;
hold on;
plot(T1,Y1,':');
plot(T2,Y2,'-.');
plot(T3,Y3,'--');
As you can see all the X values pretty much line up around 1,3,5, and 7. I want each plot to not only have a unique line, but to have the nth entry to be a certain marker style, so all second entries (around X=3) to have a square marker for example. So you should be able to identify a point by its line style and marker style. Therefore, I would like the legend to have a label for each line style and marker style. So something like this:
legend('line style 1','line style 2','line style 3','marker style 1','marker style 2','marker style 3','marker style 4');
Thanks

Accepted Answer

Brendan Hamm
Brendan Hamm on 1 Jul 2015
You would have to accomplish this as a second plot, since each Line has a MarkerStyle associated with all of the data points. To do this for the 3rd entry:
T1 = [1;3;5;7];
T2 = [0.9;2.7;5;6.8];
T3 = [1;2.9;5.1;7];
Y1 = [1;2;1;2];
Y2 = [4;5;6;4];
Y3 = [7;8;7;7];
figure;
ax = axes;
hold on;
plot(T1,Y1,':');
plot(T2,Y2,'-.');
plot(T3,Y3,'--');
ax.ColorOrderIndex = 1; % Return to the previous color index
n = 3; % The nth element should be plotted as a square
plot(T1(n),Y1(n),'s');
plot(T2(n),Y2(n),'s');
plot(T3(n),Y3(n),'s');

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!