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

1 view (last 30 days)
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:

Answers (1)

KSSV
KSSV on 3 Dec 2020
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 Comments
楠 赵
楠 赵 on 4 Dec 2020
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:

Sign in to comment.

Categories

Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!