Hello everyone, I have a small problem here. I am suppose to combine two legends from two plots which are in a 'for' loop. Whenever I try to combine two legends, only one gets printed or I get a error! In other words, I just to add the legend with the name 'TOTAL' to the legend of the first plot! I am enclosing my code and variables with this query if you like to give it a try. Thank you in advance!
for y1=1:1:ordn while feof(fid) == 0 tline = fgetl(fid); n1=n1+1; if n1 == line(y1) + 4 c = strsplit(tline,','); ord(y1).dat = fscanf(fid, ' %f, %f, %f, %f, %f, %f', [6, diffr(y1)]); ord(y1).freq = transpose(ord(y1).dat(1,:)); ord(y1).rpm = ord(y1).freq/ord1(y1)*60; RPM{y1} = ord(y1).rpm; ord(y1).total_lw = transpose(ord(y1).dat(2,:)); ord(y1).lw = transpose(ord(y1).dat(3,:)); ord(y1).lw2 = transpose(ord(y1).dat(4,:)); ord(y1).lw3 = transpose(ord(y1).dat(5,:)); ord(y1).lw4 = transpose(ord(y1).dat(6,:)); x = ord(y1).freq; r = ord(y1).rpm; f = ord(y1).freq; z1 = ord(y1).lw; z2 = ord(y1).lw2; z3 = ord(y1).lw3; z5 = ord(y1).total_lw; z4 = ord(y1).lw4; figure(20); plot(r,z5,'color',C{y1},'Linewidth',2); hold on title(sprintf('%s for the Total Time Orders',Method),'FontSize',16,'Fontweight','bold'); grid on; xlabel('RPM','FontSize',12,'Fontweight','bold'); ylabel('Schallleistung dB','FontSize',12,'Fontweight','bold'); legendInfo{y1} = ['Total Time order ' num2str(ord1(y1))]; li = legend(legendInfo,'location','southeast'); end for s=1:1:length(tempLw) div{s} = tempLw{1,s}./10; raise10{s} = 10.^div{s}; LwSum = LwSum + raise10{1,s}; LwlogSum = 10*log10(LwSum); end p1 = plot(a1,LwlogSum,'k','Linewidth',1.5); ki = legend('TOTAL','location','northeast'); %legend(li,ki);
hold off;
Best Answer