I currently have a running sample entropy code that works over a 300 sample point window. This works fine for matrices that contain only one column. I was wondering how I could amend the script in a way that it will calculate the running sample entropy for each column of a matrix with multiple columns. I'm guessing maybe a for loop may work in some way?
I have included the code with a sample example of data
X = randi(100,10000,1);OutPut = SampEn(2,0.2,X,300);function SampEnN = SampEn(dim,r,data,windowSize)%%Set-up
correl = zeros(1,2);[N,M] = size(data);SampEnN = nan(N,M);for t = windowSize+1:N tolerance = std(data(t-windowSize:t, :),'omitnan')*r; dataT = data(t-windowSize:t,:); dataMat = zeros(dim+1,windowSize-dim); for i = 1:dim+1 dataMat(i,:) = dataT(i:windowSize-dim+i-1); end for m = dim:dim+1 count = zeros(1,windowSize-dim); tempMat = dataMat(1:m,:); for i = 1:windowSize-m % calculate Chebyshev distance, excluding self-matching case
dist = max(abs(tempMat(:,i+1:windowSize-dim) - repmat(tempMat(:,i),1,windowSize-dim-i))); % calculate Heaviside function of the distance
% User can change it to any other function
% for modified sample entropy (mSampEn) calculation
D = (dist < tolerance); count(i) = sum(D)/(windowSize-dim); end correl(m-dim+1) = sum(count)/(windowSize-dim); end C = log(correl(1)/correl(2)); SampEnN(t,:) = C;endend
Best Answer