Getting Error in Matlab

Hello Experts,
As I am new to Matlab and I don’t know why this error can be removed? I am getting this error
‘Error using reshape
To RESHAPE the number of elements must not change.’
by using this code i.e,

M1m=size(message,1); %Row 
M2m=size(message,2); %Col 
% convertIng the attained message into a vector 
message= round(reshape(message,M1m*M2m,1)./256);

Any help would be appreciated.

Hello and welcome to the community!

Above you can see the syntax you’ve used. I can only suggest you to use the following one:


the [] tells MATLAB to use length(x)/N as the second dimension.

Thanks for the response. Do you mean that I should do like that?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.



You are facing the error due to the difference in elements of the output and input matrix. The count should not changed.

For example, if you know your input matrix is the size of 100, then reshape(A, 5, []) will become 5x20 matrix, or reshape(A, 5, [], 4) will become 5x5x4 matrix.

So, if you want N columns, but do not know how many rows you want or vice versa you have to use [] syntax, which tells MATLAB to use as many as necessary columns/rows to make the number of elements to be equal.