the colors red, blue, yellow repeated again in my plot, how I can give each curve in the plot different color

26 visualizaciones (últimos 30 días)
clc;
clear;
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T,'-O','LineWidth',2);
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 9 de Jun. de 2021
One way is to specify a different color in each call to the plot function:
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T,'-O','color', rand(1,3), 'LineWidth',2); % use custom color
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end
  1 comentario
Scott MacKenzie
Scott MacKenzie el 9 de Jun. de 2021
Editada: John Kelly el 16 de Dic. de 2021
Below is some modified code that increases the number of colors from 7 to 10. The additional colors are random, but you can set them to particular colors if you wish.
ax = gca;
ax.ColorOrder(8:10,:) = rand(3,3); % increase from 7 to 10 colors
hold on;
K=1:30;
for i=1:10
C_T=i*log(K);
plot_T = plot(K,C_T, '-O', 'LineWidth', 2);
hold on
grid on
title('Total Capacity of the System')
xlabel('Number of Users')
ylabel('Total Capacity (bit/s/Hz)')
legend
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Plot Customization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by