Index exceeds matrix dimensions

I run a program of Improved Dense Trajectory features Encoded by Fisher Vector, written by Bo Yang. Below shows a part of the coding.
for i=1:dtf_feat_num
feat=feats_train{i};
% L1 normalization & Square root
feat=sqrt(feat/norm(feat,1));
% Do PCA on train/test data to half-size original descriptors
fprintf('Doing PCA ...\n');
pca_coeff{i} = princomp(feat');
pca_coeff{i} = pca_coeff{i}(:, 1:floor(size(feat,1)/2))';
% dimensionality reduction
feat = pca_coeff{i} * feat;
fprintf('Training Guassian Mixture Model ...\n');
gmm{i}=gmm_gen_codebook(feat,gmm_params);
end
When i run the master.m , it shows the error below:
Index exceeds matrix dimensions.
Error in pretrain (line 57)
pca_coeff{i} = pca_coeff{i}(:, 1:floor(size(feat,1)/2))';
Can anyone help me to solve this problem? Thank you.

3 Comments

Mohamad - what are the dimensions of pca_coeff? When this error occurs, what are the values of i and 1:floor(size(feat,1)/2)?
Mohamad's answer moved here
The dimension of pca_coeff is 4x1.
The code below are the looping part:
for i=1:dtf_feat_num
feat=feats_train{i};
% L1 normalization & Square root
feat=sqrt(feat/norm(feat,1));
% Do PCA on train/test data to half-size original descriptors
fprintf('Doing PCA ...\n');
pca_coeff{i} = pca(feat');
pca_coeff{i} = pca_coeff{i}(:, 1:floor(size(feat,1)/2))';
% dimensionality reduction
feat = pca_coeff{i} * feat;
fprintf('Training Guassian Mixture Model ...\n');
gmm{i}=gmm_gen_codebook(feat,gmm_params);
end
end
Below are value of the variables in the coding:
dtf_feat_num = 4
feat = 96x985 double
floor(size(feat,1)/2) = 48
And what are the dimensions of the elements in the pca_coeff array? You may need to put a breakpoint at this line, run your code and step through it with the debugger to see what is happening.

Sign in to comment.

Answers (0)

Categories

Asked:

on 1 Mar 2019

Commented:

on 2 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!