hello everybody,
i am sharing my code and its giving some errors, i hope any of you guys will try to help me. here are 2 .m files. one is RM.m, in this file i am calling a function Train_Test.
//RM.m// ind_pin.mat fill consist of 2 sub matrix, "fea" and "gnd", "fea" is 200x21025 and "gnd" is 1x21025.clear;clcload ind_pin.mat for kk=1:3 x = sprintf('iteration = %d',kk); disp(x); for numTrain=2:4 for M=5:2:7 L=20; [feaTrain,gndTrain,feaTest,gndTest]=Train_Test(fea,gnd,numTrain); [eigvector_PCA, eigvalue_PCA] = PCA(feaTrain,0); [eigvector_Select] = RandomSelect(eigvector_PCA, 140); pca_feaTrain = feaTrain*eigvector_Select; pca_feaTest = feaTest*eigvector_Select; acc=Accury(pca_feaTrain,gndTrain,pca_feaTest,gndTest,M,L); A = sprintf('Accuracy = %6.3f',acc); disp([A '%']); end endend/Train_Test.m //functionfunction [feaTrain,gndTrain,feaTest,gndTest]=Train_Test(fea,gnd,numTrain)X = sort(gnd);temp = diff([X;max(X)+1]);count = diff(find([1;temp]));y = [X(find(temp)) count];clear X temp count;[nClass, tmp] = size(y); m = 1; for i = 1 : nClass cSampleIdx = find(gnd == y(i,1)); R = randperm(y(i,2)); for j = 1 : numTrain feaTrain((i-1)*numTrain+j,:) = fea(cSampleIdx(R(j)),:); gndTrain((i-1)*numTrain+j) = gnd(cSampleIdx(R(j))); end for j = numTrain+1 : y(i,2) feaTest(m,:) = fea(cSampleIdx(R(j)),:); gndTest(m) = gnd(cSampleIdx(R(j))); m = m+1; end end gndTrain = gndTrain'; gndTest = gndTest'; clear R i j m cSampleIdx;
when i run it gives me following errors.
"Error using vertcatDimensions of matrices being concatenated are not consistent.Error in Train_Test (line 4)temp = diff([X;max(X)+1]);Error in RMob (line 25)[feaTrain,gndTrain,feaTest,gndTest]=Train_Test(fea,gnd,numTrain);Index exceeds matrix dimensions.Error in Train_Test (line 15)feaTrain((i-1)*numTrain+j,:) = fea(cSampleIdx(R(j)),:);Error in RMob (line 25)[feaTrain,gndTrain,feaTest,gndTest]=Train_Test(fea,gnd,numTrain);
Best Answer