How to use SUM of Series in Matlab with .txt files?

2 views (last 30 days)
Hi everyone!
I have 2 files with 2 cols each one( time vs Voltage or X vs Y), I try to calculate the following series but the result is always Zero (0) , What is the mistake ?
x(n) is the input vector signal
x´(n) is the output vector signal
CODE:
ECG=csvread('ecgfile1.txt');%INPUT SIGNAL
t1 = ECG(:, 1);%TIME COL 100000X1 double DATA
v1 = ECG(:, 2);%VOLTAGE COL
Prom=csvread('ecgfile2.txt');%OUTPUT SIGNAL
t2 = Prom(:, 1); %T2 100000x1double DATA
v2 = Prom(:, 2);
N=length(t1);%
for n=1:N
PRD=(sqrt( ( (t1(n)-mean(t2(n))).^2) ./ (t1(n).^2) ))*100;
end

Answers (1)

Walter Roberson
Walter Roberson on 24 Jan 2020
num = 0;
denom = 0;
for n=1:N
num = num + (v1(n) - v2(n)).^2;
denom = denom + v1(n).^2;
end
PRD = sqrt(num ./ denom) .* 100;
Or in vectorized form:
PRD = sqrt( sum( (v1-v2).^2 ) ./ sum(v1.^2) ) .* 100;

Community Treasure Hunt

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

Start Hunting!