alexT
alexT

Reputation: 49

MATLAB - multiple plots with advanced settings

I'm getting the "String argument is an unknown option." error for the following command:

           plot(x,data1,'-mo',...
            'LineWidth',2,...
            'MarkerEdgeColor','k',...
            'MarkerFaceColor',[.49 1 .63],...
            'MarkerSize',10,...
            x,data2,'-bs',...
            'LineWidth',2,...
            'MarkerEdgeColor','k',...
            'MarkerFaceColor',[.49 1 .63],...
            'MarkerSize',10)

Interestingly the following two work without a problem:

           plot(x,data1,'-mo', x, data2, '-bs');

           plot(x,data1,'-mo',...
            'LineWidth',2,...
            'MarkerEdgeColor','k',...
            'MarkerFaceColor',[.49 1 .63],...
            'MarkerSize',10)

Upvotes: 2

Views: 582

Answers (1)

rayryeng
rayryeng

Reputation: 104504

The reason why is because you can only specify the flags for changing attributes of your plot once per plot call. As such, when you start using x and data2, and you start defining subsequent attributes, you will get an undefined error. If you want to plot both of these at the same time, consider using two separate plot calls, and using hold on to ensure that subsequent calls to plot do not clear the figure. As such:

figure;    
plot(x,data1,'-mo', 'LineWidth',2, 'MarkerEdgeColor','k',...
        'MarkerFaceColor',[.49 1 .63] 'MarkerSize',10);
hold on;
plot(x,data2,'-bs','LineWidth',2, 'MarkerEdgeColor','k',...
        'MarkerFaceColor',[.49 1 .63], 'MarkerSize',10);

Upvotes: 3

Related Questions