numerical integration with borders
Afficher commentaires plus anciens
Hello everybody,
i have the spectral response data (xy) from a camera:
x: 451x1 double y: 451x1 double (red curve in the picture)
in front of the camera, I will mount an optical filter. This filter will only transmit light in a given range. For that purpose I want to integrate the spectral response curve of the camera (the xy Data)in the range of the filter. I've read about cumtrapz, but I don't know how to tell it to matlab, especially the borders.
Many thanks for your help.
Michael

Réponses (1)
Star Strider
le 25 Sep 2017
One approach:
x = linspace(350, 1100, 2000); % Create Data
y = sin(2*pi*x/50) + 2; % Create Data
select = (x >= 600) & (x <= 650); % Create Data
xs = x(select);
ys = y(select);
int_select = cumtrapz(xs, ys); % Integrate
figure(1)
plot(x, y)
hold on
patch([xs fliplr(xs)], [zeros(size(ys)) fliplr(ys)], 'k')
hold off
grid
axis([min(x) max(x) 0 4])
text(625, 3.5, sprintf('Area = %.3f', int_select(end)))
2 commentaires
Michael Bond
le 26 Sep 2017
Modifié(e) : Michael Bond
le 26 Sep 2017
Star Strider
le 26 Sep 2017
My code worked with the data I created. I have no idea what the problem is with your getting an empty result.
One possibility could be the units your ‘xi’ data are in. You may want to check those, then create the ‘select’ limits to include the appropriate range.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!