MATLAB: Adding legend from a list in the loop divides the names

3d plotsdisplaylegendplotplotting

Hi all
I want to add the six plots in one plot a legend. which I have defined as :
Ls=['L1','L2','L3','L4','L5','L6'];
for c=1:6
plot3(v(:,1),v(:,2),v(:,3),colorcode(c),'DisplayName',Ls(c))
hold on
end
when I do this , the legend gets like :

Best Answer

  • [ ] is concatenates the char datatypes. You need to use cell data type to keep them separate.
    Ls={'L1','L2','L3','L4','L5','L6'};
    for c=1:6
    plot3(v(:,1),v(:,2),v(:,3),colorcode(c),'DisplayName',Ls{c})
    hold on
    end