Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

how to hold legend

Asked by Elysi Cochin

Elysi Cochin

on 26 Oct 2013
Latest activity Edited by Azzi Abdelmalek

Azzi Abdelmalek

on 26 Oct 2013
Accepted Answer by Azzi Abdelmalek

Azzi Abdelmalek

how to hold legend... the plot is coming correctly... but the legend is coming only for the last one.... how to hold the legend....

    col = hsv(9);
    for i = 1:cs
        plot(x, y, 'LineWidth', 2, 'color', col(j,:)); hold on
        legendInfo{i} = Info{i};
        legend(legendInfo, 'Location', 'Best'); hold all
    end

0 Comments

Elysi Cochin

Elysi Cochin

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek

Azzi Abdelmalek

on 26 Oct 2013
Edited by Azzi Abdelmalek

Azzi Abdelmalek

on 26 Oct 2013
Accepted answer

Look at this Example

t=0:0.1:10;
y1=sin(t);
y2=cos(t);
% ------Plot the first data----------
plot(t,y1);
h=legend('word1')
%-------Plot the second data---------
hold on
plot(t,y2);
str=get(h,'string')% get the previous legend
new_leg='word2'  % your new legend
h=legend([str new_leg])  % concatenate the new and the previous legend

0 Comments

Azzi Abdelmalek

Azzi Abdelmalek

Contact us