Reputation:
At compilation, "epoch" was determined to be a variable and this variable is uninitialized. "epoch" is also a function name and previous versions of MATLAB would have called the function. However, MATLAB 7 forbids the use of the same name in the same context as both a function and a variable.
function slope1_4=s(x,m)
A=xlsread(x);
slope1_4=[];
%B=xlsread(y);
%nbligneA=size(A,1);
%nbcolonneA=size(A,2);
%nbligneB=size(B,1);
%nbcolonneB=size(B,2);
for j=m %nbcolonneA
clear ini;
clear fin;
ini=epoch(:,A(1,j),1);
fin=epoch(:,A(1,j),2);
ini(ini==0)=[];
fin(fin==0)=[];
for i=1:size(ini,1)
clear f;
clear a;
clear b;
clear y;
debut=ini(i);
ending=fin(i);
interval=ending-debut+1;
a=A(debut+1:ending+1,j);
for y=1:interval
f(y)=a(y);
end
y=1:interval;
b=polyfit(y,f,1);
slope1_4=[slope1_4,b(1)];
end
end
The problem probably come from the ":" in epoch(:,A(1,j),1) but I don't know how to solve this problem..
Upvotes: 1
Views: 859
Reputation: 125874
You can't pass :
as an argument to a function. A colon is only valid as an index into a variable, so MATLAB assumes epoch
is supposed to be a variable. However, you can't extract data from a variable you haven't initialized yet, hence the error you get.
Your function epoch
expects an index (or range of indices) as the first argument. So you have to supply it with either a scalar index or a vector of indices of data that you want it to return. If you want it to return all the data (i.e. for all possible indices), but you don't know how big the data is when you call epoch
, then you can pass a colon string as an argument, like this:
ini=epoch(':',A(1,j),1);
fin=epoch(':',A(1,j),2);
Upvotes: 2