coordinates from a fitted curve

Hi,
I have some data, I want to just connect the data together. I used "linearinterp". now, I would like to have the data from the fitted curve. I mean, my data are discrete, by "linearinter" I made a continuous curve wich fills the gaps between my data. now I want to read the coordinates of the new graph, even those which are not presented as my data.
Could anyone help me please?
Thanks

2 件のコメント

darova
darova 2019 年 11 月 6 日
Can you attach the data? Show your attempts/efforts?
Show the result picture (schematically) you want to see
S  P-W
S P-W 2019 年 11 月 6 日
here is part of my data.
I want to have FWHM of these data. I know the coordinate of the Max amount: Ymax and its corresponding X.
Then I calculated the "half maximum". now I need to know the X coordinate for Y_halfmaximum on both sides of the plotted data/curve. but the point is that my data are not basically continous, so it is not granted if I have the point with the coordinate of (x, Y_halfmaximum) on each side, so I cannot then calculate delX as FWHM. I tougth maybe if I can fit a curve or simply just connect the data point together, can have the continuous data. but the point is even just by connecting the data I dont have what I need.
can you help please.
Thanks

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2019 年 11 月 6 日

0 投票

The "linearinterp" function appears to be an R function.
Use interp1 in MATLAB. Since you have to define the independent variable interpolation points as an input argument, you will have those and the interpolated points as the output from interp1.

5 件のコメント

Star Strider
Star Strider 2019 年 11 月 6 日
編集済み: Star Strider 2019 年 11 月 6 日
Try this:
D = readmatrix('test.txt', 'HeaderLines',2);
[wpw,initx,finx,midlvl] = pulsewidth(D(:,2), D(:,1))
figure
plot(D(:,1), D(:,2))
hold on
plot([initx finx], [1 1]*midlvl, '+-r')
hold off
grid
text((initx+finx)/2, midlvl, sprintf('FWHM = %.3f\n\\downarrow', wpw), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
producing:
This uses the Signal Processing Toolbox pulsewidth function.
The Signal Processing Toolbox findpeaks function produces a similar FWHM value (‘wfp’ here):
[pks,locs,wfp,p] = findpeaks(D(:,2),D(:,1), 'MinPeakHeight',2E+5)
althoughf it does not interpolate to find the beginning and end of the curve at the FWHM value. It would be necessary to use interp1 for that.
EDIT — (6 Nov 2019 at 17:03)
Using findpeaks and interp1:
D = readmatrix('test.txt', 'HeaderLines',2);
x = D(D(:,2)>50,1);
y = D(D(:,2)>50,2);
[pks,locs,w,p] = findpeaks(y, 'MinPeakHeight',2E+5);
mpy = pks/2;
xidx = [1 locs numel(x)];
for k = 1:2
idx = xidx(k):xidx(k+1);
mpx(k) = interp1(y(idx), x(idx), mpy);
end
figure
plot(D(:,1), D(:,2))
hold on
plot(mpx, [1 1]*mpy, '+-r')
hold off
grid
whm = diff(mpx);
text(mean(mpx), mpy, sprintf('FWHM = %.3f\n\\downarrow', whm), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
producing:
coordinates from a fitted curve (2) - 2019 11 06.png
Experiment to get the result you want.
S  P-W
S P-W 2019 年 11 月 6 日
Thank you.
but unfortunately I dont have the "Signal Processing Toolbox "!
Star Strider
Star Strider 2019 年 11 月 6 日
My pleasure.
I did not know that.
Replace the findpeaks call with:
[pks,locs] = max(y);
and my findpeaks code should work correctly, since there is only one peak in your data. (I just now tested it with that change and it gave the same result, and a plot the same as the second plot in my Comment.) If you have more than one peak in any other data, and you have R2017b or later, use islocalmax to identify the different peaks.
S  P-W
S P-W 2019 年 11 月 6 日
big like!
thanks a bindle.
Star Strider
Star Strider 2019 年 11 月 6 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2019 年 11 月 6 日

コメント済み:

2019 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by