How to produce a scatter plot with smooth line for this plot?

16 visualizaciones (últimos 30 días)
Attached is the capture.png which shows the desired smooth plot that I would like to have. FYP Sample Data.PNG is what I have been getting through the codes below but I need smooth plot just like the one produced in Capture.png.
Can anyone guide how can I produce scatter plot with smooth lines please similar to the Capture.PNG?
Appreciate if anyone can help me. God Bless You!
data = xlsread("sampleexceldata.xlsx") ;
K = data(1,[1 3 5]) ; % factors
data(1,:) = [];
s1 = data(:,1) ; f1 = data(:,2) ;
s2 = data(:,3) ; f2 = data(:,4) ;
s3 = data(:,5) ; f3 = data(:,6) ;
figure
yyaxis right
plot(s3,f3,'g-o',s2,f2,'b-+')
axis ([0 5 0 90])
ylabel('Force (N)');
yyaxis left
plot(s1,f1,'r-*')
axis ([0 5 0 13])
grid on
title('Force vs Displacement');
xlabel('Displacement (mm)');
ylabel('Force (N)');

Respuesta aceptada

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 24 de Mayo de 2020
Those smooth lines are interpolations between the given points. For you to have a similar result, what you need to do is find an interpolation that is suitable for your expectations about the data and then simply interpolate before plotting. An simple example can be seen below, where the difference between a linear (default) and cubic interpolation can be seen check interp1:
x = 1:10;
y = (-1).^(x);
xq = 1:0.01:10;
yq = interp1(x,y,xq,'PCHIP') ;
figure,plot(x,y,'g-o','linewidth',2)
hold on,plot(xq,yq,'linewidth',2),plot(xq(1:100:end),yq(1:100:end),'r+','linewidth',2)
  1 comentario
Ashvinder Singh Gill Surmaish Singh Gill
I did the following: But I am getting the error below. Can you tell me what is missing or wrong with this code?
data = xlsread("sampleexceldata.xlsx") ;
K = data(1,[1 3 5]) ; % factors
data(1,:) = [];
s1 = data(:,1) ; f1 = data(:,2) ;
s2 = data(:,3) ; f2 = data(:,4) ;
s3 = data(:,5) ; f3 = data(:,6) ;
ss1= 0:0.25:5;
ff1=interp1(s1,f1,ss1,'PCHIP');
ss2= 0:0.25:5;
ff2=interp2(s2,f2,ss2,'PCHIP');
ss3= 0:0.25:5;
ff3=interp3(s3,f3,ss3,'PCHIP');
figure
yyaxis right
plot(s3,f3,ss3(1:100:end),ff3(1:100:end),'g-o',s2,f2,ss2(1:100:end),ff2(1:100:end),'b-+')
axis ([0 5 0 90])
ylabel('Force (N)');
yyaxis left
plot(s1,f1,ss1(1:100:end),ff1(1:100:end),'r-*')
axis ([0 5 0 13])
grid on
title('Force vs Displacement');
xlabel('Displacement (mm)');
ylabel('Force (N)');
>> Sample2
Error using griddedInterpolant
The coordinates of the input points must be finite values; Inf and NaN are not permitted.
Error in interp1 (line 134)
F = griddedInterpolant(X,V(:,1),method);
Error in Sample2 (line 8)
ff1=interp1(s1,f1,ss1,'PCHIP');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by