MATLAB: How to remove this error : Error using horzcat Dimensions of matrices being concatenated are not consistent.

error horzcat

%taking an image
clc;
close all;
[fname,path]=uigetfile('.jpg','open a face as input for training');
fname=strcat(path,fname);
im=imread(fname);
imshow(im);
title('inputface');
c=input('Enter the class (number from 1-10)');
%%feature Extraction
F=FeatureStatistical(im);
try
load db;
F=[F c];
db=[db;F];
save db.mat db
catch
db=[F c];
save db.mat db
end
*2nd file*
function [F]=FeatureStatistical(im)
im=double(im);
m=mean(mean(im));
s=std(std(im));
F=[m s];

Best Answer

My guess is that your code is throwing the error with one of these:
F = [F c];
db = [db;F];
F = [m s];
Check the size (and perhaps class) of the elements you are attempting to concatenate.