How to plot loop items on legend
Mostrar comentarios más antiguos
Hi,
I've got a loop that uses values in a list (fRat) in each iteration. The output of the code is as expected, but I want to make sure the legend shows me which curve corresponed to which iteration value in the list. So far it's only giving me the last list item value i.e., 0.3.
I've attached the code.
Also, if i move the %plotting block from where it is now, it'll again only output one curve - the last one.
I look forward to your advice and/or feedback.
Thanks.
%range
x = 50:1000;
TL = zeros(length(x), 1); % memory pre-allocation
for fRat = [0.1, 0.15, 0.3] %list
for j = 1:length(x)
%code
%TL - desired output function
end
%plotting
y = real(TL);
semilogx(x, y)
hold on
legend(strcat('p=', num2str(fRat)))
xlabel("Frequency (Hz)")
ylabel("Transmission loss (dB)")
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
