Legend being occupied by background spectrogram

2 visualizaciones (últimos 30 días)
Sreeraj T
Sreeraj T el 19 de Nov. de 2020
Comentada: Sreeraj T el 19 de Nov. de 2020
I have code which goes like this:
clc;clear;
close all
Time=linspace(16.8,17.8,230400)';
Field=linspace(0,4,230400)';
figure('units','normalized','outerposition',[0 0 1 1])
hammng_wndw_size=4096;
window=hamming(hammng_wndw_size); %window size
noverlap=512; % the noverlaps its the no. of points for repeating the window
nfft=4096; %size of fft
fs=32; %sampling freq
[Sp,F,T,P]=spectrogram(Field,window,noverlap,nfft,fs,'yaxis');
T_forspectrogrm=T./3600+Time(1);
surf(T_forspectrogrm,F,10*log10(P),'edgecolor','none','FaceColor','interp');
axis tight;ylim([0 4]);view(0,90);
colormap(jet);
cb = colorbar(gca,'east');
cb.Position = cb.Position + [0.07 0 0 0];
cb.Label.String = '\bf log_{10}(nT^2/Hz)';
ylabel('Frequency (Hz)')
set(gca,'linewidth',1.5,'fontsize',...
12,'Layer','top');
grid off
hold on
Field4fig=Field(1:round(length(Field)/length(T)):length(Field),1);
plot(T_forspectrogrm,Field4fig,'r',...
T_forspectrogrm,Field4fig/2,'k','LineWidth',1.5)
legend({'A','B'},'FontSize',15,'Location','northwest')
ax=gca;
ax.XTickLabel=datestr(hours(ax.XTick),'HH:MM');
And whose output is like this:
My question is:
  1. As you can see from the command, I have 2 legends in the program, however, in the plot only one is showing, the other is occupied by the background spectrogram. What am I doing it and how can I rectify it?
  2. If you click on the ‘Data Cursor’ and click on the lines, we can see that the end points of both the lines is 16.82 and 18.78. How can I modify the code to start x axis from this time in hh:mm format in such a way that there are 10 evenly placed ticks in x axis?
I am usign MATLAB2016a

Respuesta aceptada

VBBV
VBBV el 19 de Nov. de 2020
hold on
Field4fig=Field(1:round(length(Field)/length(T)):length(Field),1);
F = plot(T_forspectrogrm,Field4fig,'r',...
T_forspectrogrm,Field4fig/2,'k','LineWidth',1.5)
legend(F, {'A','B'},'FontSize',15,'Location','northwest')
Try above for plotting legend
  1 comentario
Sreeraj T
Sreeraj T el 19 de Nov. de 2020
Thanks you.
It worked for question 1. Any thoughts on second question?

Iniciar sesión para comentar.

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 19 de Nov. de 2020
Editada: KALYAN ACHARJYA el 19 de Nov. de 2020
Questions 1:
You have only one legened in the provided code
legend({'A','B'},'FontSize',15,'Location','northwest')
Question 2:
Clarification needed: Do you want to start the line plot from 17:00 right?
  1 comentario
Sreeraj T
Sreeraj T el 19 de Nov. de 2020
Thank you for taking time to look into my problem.
  1. I beleive that I am giving the legends. You may try this portion
plot(T_forspectrogrm,Field4fig,'r',...
T_forspectrogrm,Field4fig/2,'k','LineWidth',1.5)
legend({'A','B'},'FontSize',15,'Location','northwest')
of code and see that I have indeed given two legends.
2. I need to start from hh:mm corresponding to 16.82, if thats possible and divide the x axis into 10 evenly space part (I have modified the question).

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by