neural network - error: Matrix dimensions must agree in matlab for building confusion matrix -
i know question has been asked before didn't answer out of them. , didn't mathworks.com i'm trying build confusion matrix ann. testsize number of testset files have.
output = sim(net,yt);%testing network confusionmatrix(10,10);%building confusion matrix i=1:(testsize-2)*10 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 whole code. it's speech recognition based on testsets , trainsets.
trainset=dir('trainset'); maxlength=0; i=3:length(trainset) file=strcat('trainset\',trainset(i).name); sub_direction=dir(file); 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'); i=3:length(testset) file=strcat('testset\',testset(i).name); sub_direction=dir(file); 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 i=3:length(trainset) file=strcat('trainset\',trainset(i).name); sub_direction=dir(file); trainsize = length(sub_direction); 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 k=1:length(sample) trainsetmatrix(i-2,j-2,k) = sample(k); end end end %equalizing testset data i=3:length(testset) file=strcat('testset\',testset(i).name); sub_direction=dir(file); testsize = length(sub_direction); 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 k=1:length(sample) testsetmatrix(i-2,j-2,k) = sample(k); end end end i=3:length(trainset) file=strcat('trainset\',trainset(i).name); sub_direction=dir(file); j=3:length(sub_direction) framesize = 160;%framing: each frame equals 8khz*20msec = 160samples frameoverlap = 80;%overlapping 50% of each frame framedtrainsetmatrix(1,:) = trainsetmatrix(i-2,j-2,1:160); k=1:floor(maxlength/80)-2 framedtrainsetmatrix(k+1,:)= trainsetmatrix(i-2,j-2,k*80:(k*80+framesize-1)); end end end i=3:length(trainset) file=strcat('trainset\',trainset(i).name); sub_direction=dir(file); j=3:length(sub_direction) window = hamming(framesize); 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 i=3:length(testset) file=strcat('testset\',testset(i).name); sub_direction=dir(file); j=3:length(sub_direction) framesize = 160;%framing: each frame equals 8khz*20msec = 160samples frameoverlap = 80;%overlapping 50% of each frame framedtestsetmatrix(1,:) = testsetmatrix(i-2,j-2,1:160); k=1:floor(maxlength/80)-2 framedtestsetmatrix(k+1,:)= testsetmatrix(i-2,j-2,k*80:(k*80+framesize-1)); end end end i=3:length(testset) file=strcat('testset\',testset(i).name); sub_direction=dir(file); j=3:length(sub_direction) window = hamming(framesize); 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); i=1:(testsize-2)*10 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 i=1:10 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 @ 167
minimum = find(m == min(m));
please help.
see documentation min
:
if matrix, min(a) row vector containing minimum value of each column.
your min(m)
call returning vector, matlab can't use ==
(inputs , b ==
must same size unless 1 scalar), illustrated test case, produces same error:
a = rand(4); test = find(a == min(a));
if you're looking index of smallest value in entire matrix, use find(a == min(a(:)));
or, more simply: [minval idx] = min(a(:))
Comments
Post a Comment