Here simply if i want to write the matlab code to find the fwhm (up to 4 or 5 digits) of like following curve, i have to find x values difference corresponding to average value of y. Since x values at average y do not lie at y data points hence i required interpolate values of x. Pls help regarding to this.
for example take below plot and data
clear all
clc
y=[];
for x=-4:5;
z=x.^2;
y=[y z];
end
y;
x=-4:5;
plot(x,y)
Here i have to find x values difference at y=12.5 to determine the fwhm ,of respective curve. How can i write in code?
Thank you.

 Akzeptierte Antwort

Star Strider
Star Strider am 26 Jul. 2020

1 Stimme

Try this:
x=-4:5;
for k = 1:numel(x)
z=x(k).^2;
y(k) = z;
end
[miny,idx] = min(y);
left_x = interp1(y(1:idx),x(1:idx), y(1)/2)
right_x = interp1(y(idx:end),x(idx:end), y(1)/2)
figure
plot(x,y)
hold on
plot([left_x right_x], [1 1]*y(1)/2, '+r')
hold off
There is no ‘full width-half-maximum’ because ther is no defined maximum. This code finds the approximate values for ‘full-width-half-minimum’ instead, since only that makes sense in this context.
.

5 Kommentare

MOHD UWAIS
MOHD UWAIS am 26 Jul. 2020
Thank you
For me it will be more beneficial in terms of maximum value of y. If i cosider maximum value of y 25, what will be change?
My pleasure!
The changes would be:
left_x = interp1(y(1:idx),x(1:idx), y(end)/2)
right_x = interp1(y(idx:end),x(idx:end), y(end)/2)
and in the plot call:
plot([left_x right_x], [1 1]*y(end)/2, '+r')
since here, the maximum value of ‘y’ is equal to ‘y(end)’. Make the appropriate changes to get the result you want, using whatever values of ‘y’ you want.
Alternatively:
left_x = interp1(y(1:idx),x(1:idx), max(y)/2)
right_x = interp1(y(idx:end),x(idx:end), max(y)/2)
and:
plot([left_x right_x], [1 1]*max(y)/2, '+r')
to use the maximum in a particular data set.
.
MOHD UWAIS
MOHD UWAIS am 27 Jul. 2020
thanks a lot
MOHD UWAIS
MOHD UWAIS am 27 Jul. 2020
can i choose max y (not y(1)) on left side in a particular data set?
Star Strider
Star Strider am 27 Jul. 2020
As always, my pleasure!
It would likely be best to use ‘max(y)’.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by