2
votes

slip_percent is plotted on y axis vs nInc(Values of 'nInc' and 'numofContacts' are obtained while running the code)

 slip_percent = cell(1,numofContacts);
     for nC=1:numofContacts
         slip_percent{nC} = ShearCapacity(:,(5*nC));
     end

Slip_percent{nC}'s are column matrices which should be plotted on same graph using different colors and legend them. If numofContacts(nC) is fixed, then the solution would be simple.

I tried the following code, but it plots all the lines in same color 'Leg' : this array contains the following elements : CaseA,CaseB,-----CaseZ,CaseAA,---,CaseZZ. Suppose numofContacts = 3, there are 3 columns in slip_percent , then the three columns must be plotted in same graph with different colour and they must be named as CaseA,CaseB and CaseC resp.

hold on
x = linspace(0,nInc);
for g=1:numofContacts
  plot(slip_percent{g})
  legend(Leg(g));
xlabel('Load Increment');
ylabel('% of Bolt Slip');
hold off
end

Can anyone help me plot the lines in different colors and how to name them ?

Thank You

1

1 Answers

2
votes

You can use legend with a string cell array argument to provide several legends.
Also try replacing hold on with hold all

hold all
for g=1:numOfContacts
    plot( slip_percent{g});
end
legend( Leg );
xlabel('Load Increment');
ylabel('% of Bolt Slip');