Joining all y-axis points by a smooth line

Dear Firends,
Need you suggestion.
I have the following matlab figure which have multiple y values for one x-point.
I want to join all the points by a smooth line as shown by the red.
If however, i use matlab plot or line function, it joing all the points according to increasing x-value and makes the plot noisy.
Can anyone suggest me how to join these points as shown by using matlab or any other program.
Thanking you.
123456.jpg

 Accepted Answer

Try this:
y = linspace(1.2, 3, 50);
x = sin(2*pi*y)*2000;
figure
plot(x, y, '-o')
grid
It would be easier if we had your data, since I do not know if they are sorted or random. If they are random, you would need to sort them first to use this approach.

7 Comments

i tried this solution..but it is required that the original shape be maintained.
fit1.png
Here is the raw data...
Sort, then plot:
[D,S] = xlsread('Book1.xlsx');
Lidx = (D(:,1) >= -4000) & (D(:,1) <= 4000);
Ds = sortrows(D(Lidx,:), 2);
figure
plot(Ds(:,1), Ds(:,2), 'o-')
grid
xlabel('U')
ylabel('Ls')
producing:
Joining all y-axis points by a smooth line - 2019 06 05.png
Thanks a lot for you reply Strider. I dont want to see the spikes. The line should be smooth. Is there anu other way?
You can get rid of some of them, but not all, because it is difficult to define outliers in your data. If you have R2018b or later, you can use the rmoutliers (link) function, or the hampel (link) function if you have R2015b or later:
[D,S] = xlsread('Book1.xlsx');
Lidx = (D(:,1) >= -4000) & (D(:,1) <= 4000);
Ds = sortrows(D(Lidx,:), 2);
Dsrm = rmoutliers(Ds(:,2),'movmedian',5); % rmoutliers
% Dsrm = hampel(Ds(:,2), 3, 0.25); % hampel
[C,ia,ib] = intersect(Ds(:,2),Dsrm, 'stable');
figure
plot(Ds(ib,1), Ds(ib,2), 'o-')
grid
xlabel('U')
ylabel('Ls')
I also experimented with filtering, and with the sgolayfilt function, none of which did as well as this code.
This is as good as it gets:
As suggested, i removed th unnessary data points and got good curve.
Thanks STAR strider..:)
final.png
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!