Hi there,
I know some basics of matlab, though I'm new to it. I use it only when I need any plot.
Now, I have some data points (x,y), which I have attached here. This is from my model output.
I want to import this file into matlab and plot this as a 2D plot in X,Y. The most important thing is that I need a smooth curve as in the attached figure named "Want.jpg". If I normally plot these points in MS excel, what I'm getting is shown in the figure named "Getting.jpg" and I don't want a plot like this.
Can anyone help me. Thanks in advance.
Cheers.

 채택된 답변

Meg Noah
Meg Noah 2020년 1월 13일
편집: Meg Noah 2020년 1월 13일

1 개 추천

First, I added a header to the xlsx file so readtable can be used properly.
myData = readtable('Data_help.xlsx');
figure()
plot(myData.x,myData.y,'+')
hold on;
ywant = 0:0.01:1;
P = polyfit(myData.y,myData.x,6);
xwant = polyval(P,ywant);
plot(xwant,ywant)
SamplePolyfit.png

댓글 수: 5

You can also polyfit the interpolated data - maybe it's a little nicer. There is a program called smooth that does a really good job, but I don't have that toolbox.
myData = readtable('Data_help.xlsx');
figure()
plot(myData.x,myData.y,'+')
hold on;
ytmp = 0:0.01:1;
xtmp = interp1(myData.y,myData.x,ytmp,'v5cubic')
P = polyfit(ytmp,xtmp,6);
ywant = 0:0.001:1;
xwant = polyval(P,ywant);
plot(xwant,ywant)
SamplePolyfit.png
Muhammadhn Muhammadh Khalid
Muhammadhn Muhammadh Khalid 2020년 1월 13일
Thanks very much Meg Noah. This is exactly what I wanted.
You mentioned about the 'smooth' program. I checked my toolbox and I have it there. In case if I want to use it, how should I use it?
Additonally, I need a small clarification about the interpolation; what is the meaning of 'v5cubic' there?
Thanks
Meg Noah
Meg Noah 2020년 1월 13일
'v5cubic' is one of many interp1 options that matlab offers. I usually use 'pchip' or 'spline'. Check the documentation.
The smooth operator can operate just on the data:
x_smoothed = smooth(x);
or you can overwrite the default sliding window length, with a number, say, 7, to have it smooth over 7 elements:
x_smoothed = smooth(x, 7);
There are some other features. It's a great algorithm. I think I have the paper somewhere, it was published in a now defunct computer journal/magazine.
Muhammadhn Muhammadh Khalid
Muhammadhn Muhammadh Khalid 2020년 1월 13일
Oh it's the 1D interpolation. I have been looking at the documentation of 'interp'. Thanks Meg Noah.
'Smooth' seems an interesting operator. I'll look for that paper as well. Thanks.
Muhammadhn Muhammadh Khalid
Muhammadhn Muhammadh Khalid 2020년 3월 2일
Hi Meg Noah, I' m trying the same thing with the attached data set. But ending up in a more curvy plot. I need a smooth plot similar, but better, than the attached figure. Thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multimodal에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by