Question

I have a problem in matlab. I want to plot a graph having 5 plots. Let me go through them. x axis for each data is from 1:500.

For plot 1 to 3, I want to place marker after every 10 values, whereas for plot 4 to 5 I want to place markers after every 5 values. Is it possible to do it ?

I followed a code something like this:

figure,
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
set(gcf,'Color','white');
plot(ObjVal1(1:10:end),'*r','LineWidth',3);
hold on;
plot(ObjVal2(1:10:end),'-.b','LineWidth',3);
plot(ObjVal3(1:10:end),'+-k','LineWidth',3);
plot(ObjVal4(1:5:end),'sm','LineWidth',3);
plot(ObjVal5(1:5:end),'.b','LineWidth',3);
hold off;
title({'Fitness Value'},'FontWeight','bold','FontSize', 12,'Color','black');
xlabel('Fitness Value --->','FontWeight','bold','FontSize', 12,'Color','black');
ylabel('Iterations --->','FontWeight','bold','FontSize', 12,'Color','black');
legend('CV GDS','CV Momentum','CV Exct LS','CV Back Track','CV Conjugate GDS');

Then I get an output like this :

enter image description here

The problem is quite evident from the picture. The plots of 1-3 is given for 50 values as the subplot is taken for each 10 iterations whereas the 4th and 5th plot is given for 100 values as the subplot is taken for each 5 iterations. I do not want to do this. Basically I want the plot of all the values but with the markers placed at each 10 iterations for plot 1-3 and at each 5 iterations for plots 4-5.

Thanks everybody in advance for your help !

Was it helpful?

Solution

Use first argument to plot to specify x-axis positions of the markers:

plot(1:10:numel(ObjVal3), ObjVal3(1:10:end),'+-k', 'LineWidth', 3);
plot(1:5:numel(ObjVal4), ObjVal4(1:5:end), 'sm', 'LineWidth', 3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top