Remove legend for specific data

3 visualizaciones (últimos 30 días)
Amir Hosein Shokouhy
Amir Hosein Shokouhy el 17 de Mzo. de 2021
Comentada: Amir Hosein Shokouhy el 30 de Mzo. de 2021
Hi.
I want to remove the legends for my vertical dash plots (data1 to data5!) . Here is my code:
figure (11)
for i=1:n1
plot(f{n1-i+1},Sx_dB{n1-i+1},'DisplayName',['Node ',num2str(n1-i+1)])
xlabel('Frequency (Hz)');
ylabel('Acceleration PSD (dB)');
title('Auto PSD')
xlim([0 round(max(w_Hz))+1])
legend
hold on
grid on
end
for j=1:n1-1
xline(w_Hz(j),'r--')
hold on
end
I would appreciate it if someone could help me with this.
Thanks,
Amir

Respuesta aceptada

ANKUR KUMAR
ANKUR KUMAR el 17 de Mzo. de 2021
Editada: ANKUR KUMAR el 30 de Mzo. de 2021
for i=1:n1
plot_lin(i)=plot(f{n1-i+1},Sx_dB{n1-i+1},'DisplayName',['Node ',num2str(n1-i+1)])
xlabel('Frequency (Hz)');
ylabel('Acceleration PSD (dB)');
title('Auto PSD')
xlim([0 round(max(w_Hz))+1])
hold on
grid on
end
for j=1:n1-1
xline(w_Hz(j),'r--')
hold on
end
legend(plot_lin,{'data1 ','data 2','data 3','data 4','data 5','data 6'})
Make sure to have sufficient legend titles in the last line of the code.
  5 comentarios
ANKUR KUMAR
ANKUR KUMAR el 30 de Mzo. de 2021
Since I do not have the data, I am generating plot for random data.
clc
clear
for i=1:4
plot_lin(i)=plot(linspace(0,2*pi,100),sin(i*linspace(0,2*pi,100)),'DisplayName',['Node ',num2str(4-i+1)])
xlabel('Frequency (Hz)');
ylabel('Acceleration PSD (dB)');
title('Auto PSD')
% xlim([0 round(max(w_Hz))+1])
hold on
grid on
end
for j=1:5
xline(j,'r--')
hold on
end
% legend(plot_lin,{'data1 ','data 2','data 3','data 4','data 5','data 6'})
legend(plot_lin)
Above code is working fine, and generating this below plot
Amir Hosein Shokouhy
Amir Hosein Shokouhy el 30 de Mzo. de 2021
Thanks Ankur, I restarted my matlab and it's working now!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by