MATLAB: How to find the width of plotted graph at selected Y-axis level

graphwidth

I want to measure the width of each signal at the y-axis's 20(TE reflection efficiency). Could you please help me with that code?

Best Answer

Try this:
lambda = linspace(0.4, 0.6); % Wavelength Vector
s = sinc(((0.47:0.02:0.55).' - lambda)*1E+2)*30; % Signal Matrix (Row Vectors)
for k = 1:size(s,1)
[maxv,idx] = max(s(k,:)); % Index Of Peak
idxv1 = idx+[-2 0];
lmda(k,1) = interp1(s(k,idxv1), lambda(idxv1), 21, 'pchip'); % Interpolate Rising Edge
idxv2 = idx+[0 2];
lmda(k,2) = interp1(s(k,idxv2), lambda(idxv2), 21, 'pchip'); % Interpolate Falling Edge
wdth(k) = lmda(k,2) - lmda(k,1); % Calculate Width
end
figure
hold on
for k = 1:size(s,1)
hp = plot(lambda, s(k,:));
plot(lmda(k,:), [1 1]*21, '+', 'Color',hp.Color) % Plot ‘+’ In Same Color As Signal
end
hold off
grid
Make appropriate changes to get my code to work with your signals. It may require some ‘tweaking’, however it should produce reasonable results.