- Joined
- 1/1/09
- Messages
- 111
- Points
- 28
I'm writting a simple program that finds outliers in data and removes them.
There's this main function named out1out2, that calls two functions; outlier1, outlier2. Function out1out2 is called from command window. For some reason I keep getting a warning that there's an error in outlier1,
.
But a quick look at the code shows that there isn't really an error. Here's the code for outlier1;
and out1out2
Do I need to "connect" functions outlier1m, outlier2 to out1out2 or something else? Maybe this is a simple question, but somehow I'm not getting what's wrong with the code. I'm grateful for any help.
There's this main function named out1out2, that calls two functions; outlier1, outlier2. Function out1out2 is called from command window. For some reason I keep getting a warning that there's an error in outlier1,
C++:
Error in ==> outlier1 at 4
num=length(data(1,:));
??? Output argument "S" (and maybe others) not
assigned during call to
"whatever\functions,scripts\outlier1.m>outlier1".
Error in ==> out1out2 at 14
[S,m]=outlier1(data1);
But a quick look at the code shows that there isn't really an error. Here's the code for outlier1;
C++:
function [S,m] = outlier1(data)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
num=length(data(1,:));
W=ones(1,num)/num;
W1=W;
pom=1;
while norm((W1-W),2)>0.05 || pom==1
pom=2;
W=W1;
m=zeros(num,1);
S=zeros(num,num);
for i=1:num
m=m+W(i)*data(:,i);
end
m=m/sum(W);
for i=1:num
S=S+W(i)*((data(:,i)-m)*(data(:,i)-m)');
end
Ma2=zeros(num,1);
for i=1:num
Ma2(i)=(data(:,i)-m)'*inv(S)*(data(:,i)-m);
if Ma2(i)>1
W1(i)=W(i)*Ma2(i);
end
end
end
end
and out1out2
C++:
function [ data, S, m ] = out1out2(data1)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
num=length(data1(1,:));
temp=num;
l=1;
detcov=zeros(num,1);
detS=zeros(num,1);
while temp>num/2
Cov=cov(data1');
detcov(l)=det(Cov);
[S,m]=outlier1(data1);
detS(l)=det(S);
[data,c]=outlier2(data1);
temp=length(data(1,:));
l=l+1;
end
figure
subplot(4,2,[1 2 3 4])
bar(1:l,detcov)
subplot(4,2,[5 6 7 8])
bar(1:l,detS)
end