Unable to perform assignment because the size of the left side is 1-by-7056 and the size of the right side is 1-by-213444

1 次查看(过去 30 天)
Hello,
I am writing a code to extract HOG features with the hope of using MATLAB to recognize a picture taken with a webcam. The code that I am having trouble with is code that is borrowed from the Face Recognition with MATLAB seminar by Avi Nehemiah. My pertinent code is as follows:
faceDatabase = imageSet('MarioImageDatabase',"recursive");
training=faceDatabase;
trainingFeatures = zeros(size(training,2)*training(1).Count,7056);
featureCount = 1;
for i=1:size(training,2)
for j = 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
trainingLabel{featureCount} = training(i).Description;
featureCount = featureCount + 1;
end
personIndex{i} = training(i).Description;
end
faceClassifier1=fitcecoc(trainingFeatures,trainingLabel)
I am getting the error "Unable to perform assignment because the size of the left side is 1-by-7056 and the size of the right side is 1-by-213444"
The problem is with the line:
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
I have tried changing the number of the .Count in the "trainingFeatures=zeros..." line, but if I change it to 213444 it says the left side is 213444 and the right side is 7056. So it appears that the numbers can be changed, I am just unsure how to get them to equal one another.
For reference, the image set is 3 photos.
The variables in my workspace and their values are as follows:
faceDatabase 1x1 imageSet
featureCount 1
i 1
j 1
training 1x1 imageSet
trainingFeatures 3x213444 double
if I change the .Count to 7056 then the trainingFeatures variable is 3x7056 double
Can you please help me make this work? Thank you in advance.

采纳的回答

KSSV
KSSV 2020-9-26
The error is clear..you have initiliazed a array with smaller dimension and you are trying to save more elements in the array.
Example:
A = zeros(3) ;
A(1,:) = rand(1,4) ; % this is error, you have to save array of size 1*3
If you know that dimensions are always same than you have to initialize as:
A = zeros(4) ;
A(1,:) = rand(1,4) ;
If you don't know the dimensions of the array, you initialize them as cell.
A = cell(4,1) ;
A{1} = rand(1,3) ;
A{2} = rand(1,4) ;
  5 个评论

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by