How to plot non equally spaced data in an equally spaced fashion and lable Xaxis with the data

1 次查看(过去 30 天)
Hi all,
I am trying to plot three variable on the double Y axis, I set "frequency" as X axis; "Tvalue" as left Y axis; "correlation" as right Y axis.I want to plot "correlation" as bar plot,Tvalue as line plot.
figure(1)
[hAxes,hBar,hLine]=plotyy(freq,T,freq,correlation,'bar','plot');%%
set(hLine,'color',[0,0,1],'LineWidth',1,'Marker','o','MarkerSize',2,...
'MarkerFace','y')
set(hAxes(1),'ylim',[-3 6])
set(hAxes(2),'ylim',[0 0.5])
set(hAxes(1),'yTick',[-3:1:6]);
set(hAxes(2),'yTick',[0:0.1:0.5]);
set(gca,'XTick',[0:0.05:1]);
xlabel('Frequency')
ylabel(hAxes(1),'Tvalue')
ylabel(hAxes(2),'correlation')
The problem I am facing is that I cannot plot the data in an equally-spaced plot . This is what I have now:

回答(1 个)

KSSV
KSSV 2020-12-3
Read about interp1. USe interpolation and make the data even. Let F, T be your column data.
m = length(F) ;
Fi = linspace(min(F),max(F),m) ;
Ti = interp1(F,T,Fi) ;
plot(Fi,Ti)
  5 个评论
楠 赵
楠 赵 2020-12-4
Sorry, I still cannot figur out how to use xticks to present data from"freq".
freq=1./(period/10);
freq=freq(1,29:108);
freq_l = 1:length(freq);
figure(2)
Ti = T(numch,:);
Ci = coher_mt(numch,:);
%Fi = linspace(min(freq),max(freq),m) ;
%Ti = interp1(freq,T(numch,:),Fi) ;
%Ci = interp1(freq,coher_mt(numch,:),Fi) ;
[hAxes,hLine1,hLine2]=plotyy(freq_l,Ti,freq_l,Ci,'plot','stem');%%
set(hLine2,'LineWidth',1,'Marker','o','MarkerSize',2,...
'MarkerFace','y')
set(hLine1,'LineWidth',1,'Marker','o','MarkerSize',2)
set(hAxes(1),'ylim',[-3 6],'yTick',[-3:1:6])
set(hAxes(2),'ylim',[0 0.5],'yTick',[0:0.1:0.5])
this is what I have now:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by