I am trying to find a function value using other 3 functions. I don't know why i am getting an error. Please help me with this.

1 回表示 (過去 30 日間)
This is my code:
file= 'Feb23.txt'
rawdata= textread(file)
rawdata(:,2) = [];
cropdata= transpose(rawdata(38401:128401))
%Applying Gaussian expansion filter for signal smoothing
alpha = 0.01;
filterdata = filter(alpha, [1 alpha-1], cropdata);
%------------------Calculating MSE--------------------%
n=2
h= 1
fac=12
mse= msentropy(filterdata,n,h,fac)
figure;
plot(mse)
My first function:
% Function for calculating multiscale entropy
% input: signal
% m: match point(s)
% r: matching tolerance
% factor: number of scale factor
% sampenc is available at http://people.ece.cornell.edu/land/PROJECTS/Complexity/sampenc.m
function e = msentropy(input,m,r,factor)
y=input;
y=y-mean(y);
y=y/std(y);
for i=1:factor
s=coarsegraining(y,i);
sampe=sampenc(s,m+1,r);
e(i)=sampe(m+1);
end
e=e';
Second Function:
function output = coarsegraining(input,factor);
n=length(input);
blk=fix(n/factor);
for i=1:blk
s(i)=0;
for j=1:factor
s(i)=s(i)+input(j+(i-1)*factor);
end
s(i)=s(i)/factor;
end
output=s';
Third Function
function [e,A,B]=sampenc(y,M,r);
%function [e,A,B]=sampenc(y,M,r);
%
%Input
%y input data
%M maximum template length
%r matching tolerance
%
%Output
%
%e sample entropy estimates for m=0,1,...,M-1
%A number of matches for m=1,...,M
%B number of matches for m=0,...,M-1 excluding last point
n=length(y);
lastrun=zeros(1,n);
run=zeros(1,n);
A=zeros(M,1);
B=zeros(M,1);
p=zeros(M,1);
e=zeros(M,1);
for i=1:(n-1)
nj=n-i;
y1=y(i);
for jj=1:nj
j=jj+i;
if abs(y(j)-y1)<r
run(jj)=lastrun(jj)+1;
M1=min(M,run(jj));
for m=1:M1
A(m)=A(m)+1;
if j<n
B(m)=B(m)+1;
end
end
else
run(jj)=0;
end
end
for j=1:nj
lastrun(j)=run(j);
end
end
N=n*(n-1)/2;
B=[N;B(1:(M-1))];
p=A./B;
e=-log(p);
The error is on this line: mse= msentropy(filterdata,n,h,fac) Index in position 1 is invalid. Array indices must be positive integers or logical values.
Also, there is a warning: Warning: Function j has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.
  1 件のコメント
Bob Thompson
Bob Thompson 2018 年 8 月 6 日
編集済み: Bob Thompson 2018 年 8 月 6 日
It seems like the issue is with the filterdata input to msentropy. What exactly is filterdata? My guess is that while it is trying to use filterdata within msentropy it is running into a situation where you divided an odd integer by two, or something similar.
It's very possible blk=fix(n/factor); doesn't produce an integer, which could cause a problem for the loop that follows it.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by