Normalize and integrate a curve

Hello!
If I want to normalize and integrate this curve, how should I do it?
clc
clear all
Data1=importdata('J30.txt');
x=Data1(:,1);
y=Data1(:,2);
plot(x,y)

댓글 수: 2

John D'Errico
John D'Errico 2020년 3월 10일
trapz won't integrate it? Gosh, I thought it was supposed to do that.
What does normalize mean to you? Divide by the integral perhaps?
Pouyan Msgn
Pouyan Msgn 2020년 3월 10일
yes, If I want to devide by the integral how should I do?

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

답변 (1개)

Image Analyst
Image Analyst 2020년 3월 10일

0 개 추천

Try this:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
Data1=importdata('J30.txt');
x=Data1(:,1);
y=Data1(:,2);
% Plot original data.
subplot(3, 1, 1);
plot(x, y, 'LineWidth', 2);
grid on
title('Original data', 'FontSize', fontSize);
% Normalize by dividing by y Max
y2 = y / max(y);
% Plot normalized data.
subplot(3, 1, 2);
plot(x, y2, 'LineWidth', 2);
grid on
title('Normalized by Max Y signal', 'FontSize', fontSize);
% Find the area under the original y curve
area = trapz(y)
% Normalize by dividing by y Max
y3 = y / area;
area3 = trapz(y3)
% Plot normalized data.
subplot(3, 1, 3);
plot(x, y3, 'LineWidth', 2);
grid on
title('Normalized by Area under the curve', 'FontSize', fontSize);

댓글 수: 7

Pouyan Msgn
Pouyan Msgn 2020년 3월 10일
Thank you for the help! but one question why do you integrate by y and not both vectors?
I tried first with
clc
clear all
Data1=importdata('J30.txt');
x=Data1(:,1);
y=Data1(:,2);
X=x/norm(x);
Y=y/norm(y);
I=trapz(X,Y);
But why it is not correct ?
Image Analyst
Image Analyst 2020년 3월 10일
Because when I used trapz(x, y) it mysteriously gave me a negative area!
The negative area is due to the independent variable decending (essentially going right-to-left rather than left-to-right).
Data1 = flipud(Data1);
will likely result in a positive area.
Image Analyst
Image Analyst 2020년 3월 10일
Thanks Star. I didn't notice that x was going in the opposite direction.
Star Strider
Star Strider 2020년 3월 10일
My pleasure. That’s always the first thing I check if the result looks strange!
Pouyan Msgn
Pouyan Msgn 2020년 3월 10일
편집: Pouyan Msgn 2020년 3월 10일
but how should the answer be right now? Must I normalize the x axis?
Image Analyst
Image Analyst 2020년 3월 10일
We don't know exactly what you want. Only you know that. I made two guesses as to what you possibly might want. Does any of them look like what you might want?

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

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2020년 3월 10일

댓글:

2020년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by