errors in using RESHAPE FUNCTION......PLEASE HELP ME.
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
0 commentaires
Réponses (2)
Sulaymon Eshkabilov
le 6 Juin 2021
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.
0 commentaires
Steven Lord
le 6 Juin 2021
Modifié(e) : Steven Lord
le 6 Juin 2021
More likely than not your image_Container variable has 3 or more dimensions.
x = randi(10, [2 3 4]);
sz = size(x)
sz1 = size(x, 1)
sz2 = size(x, 2)
y = reshape(x, sz1*sz2, 1)
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
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!