MATLAB: How to remove this error

error

1.i have 50 images
2.my code produces feature vector of size 512 by 512 of 50 images using a for loop
3. i am using reshape function to make matrix of 512 by 512 into 1 by 512*512=262144 vector. similarly for 50 images i need to do the same to get the final mat file of dimension 50 rows and 262144 columns.
4. whenever i try to save this vector. i always get this error
Subscripted assignment dimension mismatch.
Error in mathworks (line 19)
Result(i,:) = fv;
4. fv is producing a mat file containing 1 by 262144 feature vectors.As error occur during the first image(am using for loop to do the same process for all 50 images)
5. The code is attached please tell me the problem

Best Answer

You have this line:
fv= reshape(fv,i,[]);
This reshapes fv to have 1 row and 262144 rows when i=1, and 2 rows and 262144/2=131077 the second iteration when i=2. So now fv is not a vector anymore but a matrix of size 2 rows by 131077 columns. You can't stick a matrix into an array where you're specifically specifying that the data should go ONLY into columns like this:
Results(i,:) = fv;
If you want fv to be a row vector of 262144 columns, then you need to do this:
fv = reshape(fv, 1, 262144);