errors in using RESHAPE FUNCTION......PLEASE HELP ME.

Error using reshape
To RESHAPE the number of elements must not change.
Error in load_database (line 10)
all_Images(:,(i-1)*5+j)=reshape(image_Container,size(image_Container,1)*size(image_Container,2),1);

回答(2 个)

Note that while using reshape(), size of an array to be reshaped must be compatible with its being reshape. E.g.:
A = randi([0, 5], 5, 4);
B1 = reshape(A, 3, 3) % Does not work because of the size mismatch
B2 = reshape(A, 3, 4) % Does not work because of the size mismatch
B3 = reshape(A, 2, 10) % Works perfectly well!
Thus, check the size of your array in the position of [A] vs. sizes to be reshaped before proceeding reshape operation.
More likely than not your image_Container variable has 3 or more dimensions.
x = randi(10, [2 3 4]);
sz = size(x)
sz = 1×3
2 3 4
sz1 = size(x, 1)
sz1 = 2
sz2 = size(x, 2)
sz2 = 3
y = reshape(x, sz1*sz2, 1)
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
You can't stuff 24 elements (since x is 2-by-3-by-4) into a 6-by-1 vector.
If you want to reshape the array into a column vector, two ways to do this are to use the colon index or to use reshape and use either [] (to make reshape calculate the size in that dimension) or numel.
y1 = x(:);
y2 = reshape(x, [], 1);
y3 = reshape(x, numel(x), 1);
whos x y1 y2 y3

类别

帮助中心File Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by