errors in using RESHAPE FUNCTION......PLEASE HELP ME.
    6 次查看(过去 30 天)
  
       显示 更早的评论
    
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 个评论
回答(2 个)
  Sulaymon Eshkabilov
      
 2021-6-6
        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 个评论
  Steven Lord
    
      
 2021-6-6
        
      编辑:Steven Lord
    
      
 2021-6-6
  
      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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


