MATLAB: Subscripted assignment dimension mismatch

MATLAB

x = zeros ( 2, noOfSamples );
x ( :, sample ) = [(cell2mat(dbFeaturesTop(sample))) (cell2mat(dbFeaturesSide(sample)))];
my code as above, my dbFeaturesTop and Side are a matrix with 700*128 after I run the code it gave me error as below Please may i know which part causes this?Is it the sample?
Subscripted assignment dimension mismatch.
Error in FYPGUI>btnTrainNeuralNetwork_Callback (line 411)
x ( :, sample ) = [(cell2mat(dbFeaturesTop(sample)))
(cell2mat(dbFeaturesSide(sample)))];

Best Answer

When you use [A B] then you are asking for horzcat(A,B) -- pasting A and B "side by side", forming something that has a width of at least 2 (unless one of A or B is empty.)
When you convert the dbFeaturesTop or dbFeaturesSide entries to matrix (cell2mat), if there is more than one row in what you convert, the result would have multiple rows.
And then if you [] the two items with multiple rows together, you would have height as well as width.
In the assignment to x(:,sample), what you are assigning must be a scalar or a vector. If it is a vector it can be either a row vector or a column vector -- if it is a row vector then even though you are assigning into a column vector, it will still work. But, if the item you are assigning has both height and width, then you cannot store that rectangular object into the column vector x(:,sample)
You have not said enough about your values and intent for us to suggest the fix in your situation.