필터 지우기
필터 지우기

How to plot non equally spaced data in an equally spaced fashion.

조회 수: 8 (최근 30일)
RFR
RFR 2017년 2월 21일
댓글: 楠 赵 2020년 12월 4일
I am trying to plot some data:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
The problem I am facing is that I cannot plot the data in an equally-spaced grid plot (including the tick locations). This is an example of what I want to achieve:
Thanks for your help in advance. Raul

채택된 답변

Star Strider
Star Strider 2017년 2월 21일
See if this does what you want:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
xt = [10 50 100 500 1000 1500 2000 2500 3000 3500];
xv = 1:length(xt);
yv = interp1(x, y, xt, 'linear', 'extrap'); % Extrapolate The ‘3500’ Value
figure(1)
plot(xv, yv) % Plot Interpolated Values Against ‘xv’
grid
set(gca, 'XTickLabel',xt) % Label Ticks As ‘xt’
ylabel('Accuracy (%)')
If you do not want to extrapolate to 3500, the code would be:
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
xv = 1:length(x);
figure(1)
plot(xv, y) % Plot Interpolated Values Against ‘xv’
grid
set(gca, 'XTickLabel',x) % Label Ticks As ‘xt’
ylabel('Accuracy (%)')
  댓글 수: 5
楠 赵
楠 赵 2020년 12월 4일
I use the script you suggest to plot the figure and I got the figure like this, now I want to present the value from "x" not from "xv", how can I set x axis value from "x" ? this is what I have now:

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2017년 2월 21일
x=[10 50 100 500 1000 1500 2000 2500 3000]; %data points
y=[74.6 88.8 89.6 92.1 92.5 88.8 88.8 87.9 85.4]; %accuracy(%)
N = 100 ;
xi = linspace(min(x),max(x),N) ;
yi = interp1(x,y,xi) ;
plot(x,y,'r') ;
hold on
plot(xi,yi,'.b')
  댓글 수: 1
RFR
RFR 2017년 2월 21일
Thanks for your answer, but your solution doesn't produce a equally spaced graph. For x(1)=10, x(2)=50, and x(3)=100, the distance between points is not equally spaced as the rest of the data (=500). I need to plot all the points with the same distance in the x axis like the sample figure. Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by