Error: subscripted assignment dimension mismatch for loop

Hello,
The error I get is :
subscripted assignment dimension mismatch at line 7
for j = 1:152
mhi_fig = sprintf('data%d.png', j);
img = imread(mhi_fig);
testFeatures(j,:) = extractHOGFeatures(img);
end
Why does this happen? and what is the solution?

Answers (1)

How many columns does testFeatures have? Does it have the same number of columns as the number of values that extractHOGFeatures() returns? It must. For example if extractHOGFeatures returns 4 numbers, then testFeatures must have 4 columns to take all those 4 values and put one value per column in row j.

2 Comments

I have the same problem...the reason I understand but what is the solution? what matlab code should be in that case to assure that the number of columns is the same? thank you.
currentfeatures = extractHOGFeatures(img);
testFeatures(j, 1:length(currentfeatures)) = currentfeatures;
This code would silently expand the width of the testFeatures matrix if a file with more features was encountered, and will silently put in a smaller number of features if that is what is returned.
Basically the trigger for this problem is that images of different sizes are being read and the program has not been constructed to handle that.

Sign in to comment.

Tags

Asked:

on 2 May 2015

Commented:

on 8 May 2015

Community Treasure Hunt

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

Start Hunting!