Getting an error Product of known dimensions, 9600, not divisible into total number of elements, 1200 while reshaping. How to solve this issue

10 views (last 30 days)
vale is 1x1200
nfft=1200 ; % number of frequency samples
Navg= 8; % number of DFT's to be averaged
N= nfft*Navg; % number of time samples
n= 0:N-1; % time index
w= hamming(nfft); % window function
window= w.*sqrt(nfft/sum(w.^2)); % normalize window for P= 1 W
%
% Create matrix xMatrix with Navg columns,
% each column a segment of x of length nfft
xMatrix= reshape(vale,nfft,Navg,[]);

Answers (1)

Walter Roberson
Walter Roberson on 24 Feb 2020
You have 1200 elements in vale. nfft is the same. Navg is 8. You are trying to reshape the 1200 elements to be 1200 by 8 by whatever you can get. But that is a minimum of 9600 elements which does not fiy.
Unless you were thinking that the third dimension you were reshaping to is only 1/8 element long so that 1200 x 8 x (1/8) would somehow work. But dimension lengths must be integers.
  2 Comments
Hari raj
Hari raj on 24 Feb 2020
when i do reshaping, my error is To RESHAPE the number of elements must not change. How to solve this issue?
Walter Roberson
Walter Roberson on 24 Feb 2020
In MATLAB, arrays are stored in memory "down" columns. The first entry in the matrix A corresponds to A(1,1). The second location in memory corresponds to A(2,1), then 3,1 and so on until the number of rows is reached, such as A(1024,1). After all the entries for the first row, there are all the entries for the second row, A(1,2), A(2,2) and so on down to the last row such as A(1024,2). This continues to the last column, such as A(1024,8)
Now if you already have all this stored in memory, then without touching the memory you can put on a different header such as it being 512 x 16 instead of 1024x8. The first 512 would be A(1,1) to A(512,1), and the next element without moving in memory would get relabeled for indexing purposes from A(513,1) to A(1,2), then what was A(514,1) gets relabeled A(2,2) and so on. What was the first element of the the second row now gets relabeled to A(1,3) and so on. Eventually what was A(:, 8) would get relabeled to be columns 15 and 16 in the new array.
This operation of relabeling how you index an element without moving elements in memory is named reshape(). It always ends up with an array exactly the same size as the original, just indexed differently.
The reverse is also true: if you ask to reshape() and the new size you ask for does not exactly match the number of elements in the original array then the reshape is not permitted, because that would be more than just changing the labels used, and would require adding more elements or removing elements.
It follows from all of this that in any situation where you want the number of elements to change, then reshape() is the wrong operation.

Sign in to comment.

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!