Hi, I have read some of the previous solutions on this problem but they so far haven't worked for me. I cannot get the legend to replicate the colours of the graph itself. A solution I saw on another thread said I should make sure the whole matrix is being plotted, by incorporating (1,:) afterwards. This didn't work for me as it meant some lines wouldn't plot at all.
Any suggestions would be greatly appreciated!
clearclose allclcM = [30,10000,6,230]; %Array containing system masses (kg)
D = [5, 25, 0.5, 2]; %Array containing mission durations (years)
powerP = [200, 4000, 250, 400]; %Array containg peak power values (W)
M_ps = 0.15.*M; %Power system mass available (kg)
powerSpec = powerP./M_ps; %Specific power of each mission (W/kg)
t=linspace(0,25,1000);powerSpec_SC1 = zeros(length(t));powerSpec_SC1 = zeros(length(t));powerSpec_RTG1 = zeros(length(t));powerSpec_RTG2 = zeros(length(t));for n=1:length(t); T=t(n); powerSpec_SC1(n)=37*(1-0.15).^T; powerSpec_SC2(n)=49*(1-0.1).^T; powerSpec_RTG1(n)=98000*exp((-log(2)*T)/0.411); powerSpec_RTG2(n)=240*exp((-log(2)*T)/28.3); endfigureh1=semilogy(t,powerSpec_SC1,'r');hold onh2=semilogy(t,powerSpec_SC2,'b');hold onh3=semilogy(t,powerSpec_RTG1,'k');hold onh4=semilogy(t,powerSpec_RTG2,'k');hold onh5=plot(5,200,'ro','LineWidth',2);hold onh6=plot(25,4000,'go','LineWidth',2);hold on h7=plot(0.5,250,'bo','LineWidth',2);hold onh8=plot(2,400,'ko','LineWidth',2);xlabel('Time (years)');ylabel('Specific Power (W/kg)');title('Specifc Power over time');set(gca,'ylim',[1 1000000])legend([h1, h2, h3, h4, h5, h6, h7, h8],'Solar Array 1','Solar Array 2','RTG1','RTG2','Mission 1','Mission 2','Mission 3','Mission 4')hold off
Best Answer