MATLAB: Some part of this code

general coding

In the following code:
I do not understand what the two following lines do:
cindex(border(cv:cv+1))=[];
vindex=index(border(cv:cv+1));
I would appreciate if someone can help me with this.
Thanks,
———————————————–
% the main code
rand('state',0)
wine=wk1read('wine.wk1'); %M = wk1read(filename) reads a WK1 spreadsheet file into the matrix M. The filename input is a string enclosed in single quotes.
wine=[wine(:,2:14) wine(:,1)]; % seems they kept the first column for validation
NI=13; % 13 column is remained
NT=length(wine); %finds the number of elements along the largest dimension of an array.
data=wine;
close all
ptypes= {'.' 'o' 'x' '+' '*' 's' 'd' 'v' '^' 'p' 'h'};
components= {'Alcohol' 'Malic acid' ...
'Ash' 'Alcalinity ash' 'Magnesium' ...
'Tot. Phenols' 'Flavonoids' 'Non-flav.Phen.' ...
'Proanthoc.' 'Color intesity' 'Hue' ...
'OD280/OD315' 'Proline'}; % 13 features
[data,meanp,stdp] = prestd(data');%step 1, Preprocess data so that its mean is 0 and the standard deviation is 1, data is matrix of normalized input vectors
data=data'; %transpose
data(:,end)=wine(:,end);%

label=data(:,end);
feat=[1:13];
feat=[ 1 5 7 11 13] % seems they randomly selected 5 of the 13 columns (the features or compontents) for estimation and classification, so we can change this selected columns to see which combination works better
%feat=[6 8 11 12 13]
%Ten fold cross validation
N=size(data,1); % m = size(X,dim) returns the size of the dimension of matrix X specified by scalar dim.
index=randperm(N); %p = randperm(n) returns a row vector containing a random permutation of the integers from 1 to n inclusive.
%p = randperm(n,k) returns a row vector containing k unique integers selected randomly from 1 to n inclusive.
border=round(linspace(1,N,11)); % create 11 points between 1 and eleven
%The linspace function generates linearly spaced vectors. It is similar to the colon operator ":", but gives direct control over the number of points.
%y = linspace(a,b) generates a row vector y of 100 points linearly spaced between and including a and b.
%y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b. For n < 2, linspace returns b.
%rounds the elements of X to the nearest integers.
for cv=1:10
cindex=index;
cindex(border(cv:cv+1))=[];
vindex=index(border(cv:cv+1));
c=3;
nlabel=3;
[F,C,P,V,D,J,M] = gkfast(data(cindex,feat),c,2,1e-3);
%[F,C,P,Pi,M] = GGclust(data(:,feat),F,2,1e-6,[],[],0,1);
py=eye(c);
s=1;
IDA=1;
[F,C,P,Pi,M,py] = sGGclust([data(cindex,feat) data(cindex,end)],F,2,1e-6,IDA,s);
Ff=F;
if s==0
py=round(py);
end
reclust1=0;
if reclust1
for i=1:1
temp=abs(py-0.5);
[index,dump]=find(temp==min(min(temp)));
index=index(1);
temp=py(index,:);
in=find(temp==max(temp));
c=c+1
F=[F F(:,index)];
F(find(label==in),end)=0
F(find(label~=in),index)=0;
[F,C,P,Pi,M,py] = sGGclust([data(:,feat) data(:,end)],F,2,1e-6,IDA,s);
if s==0
py=round(py);
end
Ff=F;
end
end
reclust2=0;
if reclust2
for i=1:1
[F]=fuzeval(data(:,feat),C,M,Pi);
F=F*py;
[mi,mj]=max(F');
missi=(label~=mj');
index=find(missi>0);
c=c+1;
F=[Ff Ff(:,end)];
F(index,end)=1;
F(index,1:end-1)=0;
[F,C,P,Pi,M,py] = sGGclust([data(:,feat) data(:,end)],F,2,1e-6,IDA,s);
if s==0
py=round(py);
end
Ff=F;
end
end
%Feature reduction
for i=1:0
[index,C,M]=featsel(C,M,Pi);
feat(index)=[];
end
[F]=fuzeval(data(:,feat),C,M,Pi);
F=F*py;
T=real(F);
res=[];
for i=1:nlabel
res=[ res round(T(:,i)).*data(:,end)]; %
end
colorset=['r' 'b' 'g' 'k' 'm'];
%Plot the Mem functions
data=data(:,1:end-1);
close all
figure(1)
for i=1:size(data(:,feat),2);
xd = min(data(:,feat(i))):0.0001:max(data(:,feat(i)));
subplot(ceil(size(data(:,feat),2)/5),5,i)
hold on
for j=1:c
iM=M(:,:,j);
y1 = exp(-1/2*(xd-C(j,i)).^2*iM(i,i));
xd1=xd.*repmat(stdp(feat(i)),size(xd,1),1)+meanp(feat(i));
plot(xd1,y1,colorset(j),'linewidth',1.5)
axis([min(xd1) max(xd1) 0 1]);
end
xlabel(components{feat(i)})
hold off
end
%res=[res(:,3) res(:,1) res(:,2)];
%miss=[find(res(:,1)==2);find(res(:,1)==3);find(res(:,2)==1); ...
% find(res(:,2)==3);find(res(:,3)==1);find(res(:,3)==2)];
[i,j]=max(F');
miss=sum(label~=j')
(1-miss/size(data,1))*100
end

Best Answer

  • The first line removes some elements of the cindex array - why, I have no idea. The second line assigns vindex to something - again I have no idea why. It's hard to read code and understand that's formatted like a fiction novel instead of a computer program.