I know this question has been asked before but I didn't get the answer out of them. And I also didn't get much from mathworks.com I'm trying to build the confusion matrix for ANN. testSize is the number of testSet files that I have.
output = sim(net,Yt);%testing network
confusionMatrix(10,10);%building confusion matrix
for i=1:(testSize-2)*10
for j=1:10
m(j) = abs(output(i,i)-1);
end
minimum = find(m == min(m));
confusionMatrix(floor((i-1)/(testSize-2)) + 1,minimum) = confusionMatrix(floor((i-1)/(testSize-2))+1);
end
and below is my whole code. It's for speech recognition based on testSets and trainSets.
TrainSet=dir('TrainSet');
maxLength=0;
for i=3:length(TrainSet)
File=strcat('TrainSet\',TrainSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
path=strcat(File,'\',sub_direction(j).name);
sample=wavread(path); % Reading Files
if(length(sample) > maxLength)
maxLength = length(sample);
end
end
end
TestSet=dir('TestSet');
for i=3:length(TestSet)
File=strcat('TestSet\',TestSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
path=strcat(File,'\',sub_direction(j).name);
sample=wavread(path);
if(length(sample) > maxLength)
maxLength = length(sample);
end
end
end
%Equalizing Trainset data
for i=3:length(TrainSet)
File=strcat('TrainSet\',TrainSet(i).name);
sub_direction=dir(File);
trainSize = length(sub_direction);
for j=3:length(sub_direction)
path=strcat(File,'\',sub_direction(j).name);
trainSetMatrix(i-2,j-2,:) = zeros(1,maxLength);
sample=wavread(path); % Reading Files
for k=1:length(sample)
trainSetMatrix(i-2,j-2,k) = sample(k);
end
end
end
%Equalizing Testset data
for i=3:length(TestSet)
File=strcat('TestSet\',TestSet(i).name);
sub_direction=dir(File);
testSize = length(sub_direction);
for j=3:length(sub_direction)
path=strcat(File,'\',sub_direction(j).name);
testSetMatrix(i-2,j-2,:) = zeros(1,maxLength);
sample=wavread(path); % Reading Files
for k=1:length(sample)
testSetMatrix(i-2,j-2,k) = sample(k);
end
end
end
for i=3:length(TrainSet)
File=strcat('TrainSet\',TrainSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
frameSize = 160;%framing: each frame equals to 8khz*20msec = 160samples
frameOverlap = 80;%overlapping is 50% of each frame
framedTrainSetMatrix(1,:) = trainSetMatrix(i-2,j-2,1:160);
for k=1:floor(maxLength/80)-2
framedTrainSetMatrix(k+1,:)= trainSetMatrix(i-2,j-2,k*80:(k*80+frameSize-1));
end
end
end
for i=3:length(TrainSet)
File=strcat('TrainSet\',TrainSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
window = hamming(frameSize);
for k=1:floor(maxLength/80)-1
windowedFrame(k,:) = framedTrainSetMatrix(k,:).*window';
LinearPredictiveCoding(k,:) = lpc(windowedFrame(k,:),12);
lpcResult(k,:) = LinearPredictiveCoding(k,2:13);
end
coefficient=12*(floor(maxLength/80)-1);
X((i-3)*(trainSize-2)+(j-2),:)=reshape(lpcResult,1,coefficient);
end
end
for i=3:length(TestSet)
File=strcat('TestSet\',TestSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
frameSize = 160;%framing: each frame equals to 8khz*20msec = 160samples
frameOverlap = 80;%overlapping is 50% of each frame
framedTestSetMatrix(1,:) = testSetMatrix(i-2,j-2,1:160);
for k=1:floor(maxLength/80)-2
framedTestSetMatrix(k+1,:)= testSetMatrix(i-2,j-2,k*80:(k*80+frameSize-1));
end
end
end
for i=3:length(TestSet)
File=strcat('TestSet\',TestSet(i).name);
sub_direction=dir(File);
for j=3:length(sub_direction)
window = hamming(frameSize);
for k=1:floor(maxLength/80)-1
windowedFrame(k,:) = framedTestSetMatrix(k,:).*window';
LinearPredictiveCoding(k,:) = lpc(windowedFrame(k,:),12);
lpcResult(k,:) = LinearPredictiveCoding(k,2:13);
end
coefficient=12*(floor(maxLength/80)-1);
Y((i-3)*(testSize-2)+(j-2),:)=reshape(lpcResult,1,coefficient);
end
end
Xt = transpose(X);
T(10,1900);
hiddelLayer=1158;
net=newff(Xt,T,hiddelLayer);%building network
net.divideParam.trainRatio=0.2;
net.efficiency.memoryReduction=60;
net=train(net,Xt,T);%training network
Yt = transpose(Y);
output = sim(net,Yt);%testing network
%building confusion matrix
confusionMatrix(10,10);
for i=1:(testSize-2)*10
for j=1:10
m(j) = abs(output(i,i)-1);
end
minimum = find(m == min(m));
confusionMatrix(floor((i-1)/(testSize-2)) + 1,minimum) = confusionMatrix(floor((i-1)/(testSize-2))+1);
end
for i=1:10
for j=1:10
confusionMatrix(i,j) = confusionMatrix(i,j)/(testSize-2);
end
end
The full error is:
??? Error using ==>
eq
Matrix dimensions must agree.Error in ==> test at 167
minimum = find(m == min(m));
Please help.