How to resolve an error for undefined function or variable 'x' within a function?
이전 댓글 표시
I am trying to run code that calls in the function AMI from file (AMI.m) and it keeps giving me an error:
"undefined function or variable 'x' for line 46 A=sparse(x);
function [tau,v_AMI]=AMI(data, L)
N=length(data);
bins=128; %number of bins used for histogram calculation
epsilon = eps;
data = data - min(data); % making all the data points positive
data = 1+ floor(data/(max(data)/(bins-epsilon))); %scaling the data
v=zeros(L,1); %create a zero vector
overlap=N+1-L;
increment= 1/overlap;
one = ones(overlap,1); %create a column vector with all elements being one
pA = sparse (data(1:overlap),one,increment);
for lag = 0: L -1
pB = sparse(one, data(1+lag:overlap+lag), increment);
pAB = sparse(data(1:overlap),data(1+lag:overlap+lag),increment);
[A, B, AB]=find(pAB);
v(lag+1)=sum(AB.*log2(AB./(pA(A).*pB(B)'))); %Average Mutual Information
end
v_AMI=v;
for i = 1: length(v)-1
if (find((v(i)<v(i+1))&&(v(i)<v(i-1)))) == 1
x(i)=i;
end
end
A=sparse(x);
A=find(A);
tau=A(1); % tau = 1st min(I(time_lag))
end
The code used to call in the function is:
directory_name = uigetdir(pwd,'Select data directory');
directory_name = ([directory_name '/']);
files = dir([directory_name,'*txt']);
namer = struct2cell(files);
if isempty(files)
msgbox('No raw files in this directory')
end
for i=1:length(files)
filename = char(namer(1,i));
data = load([directory_name filename]);
L=32;
[tau,v_AMI]=AMI(data, L); %Find the first minimum average mutual information
end
It is also giving me an error for the line calling in the AMI function : [tau,v_AMI]=AMI(data, L);
How could I resolve these errors? The code is supposed to calculate a tau and v_AMI for each data .txt file containing a single column of numbers.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!