-4

I have a matrix with the dimension 65536x2 which I want to use with another of dimension 256x256. How can I change the first matrix dimension to be 256x256? I tried reshape as follows:

 N=reshape(u,256,256);

But, got the following error:

Error using reshape
To RESHAPE the number of elements must not change.

What should I do in this case?

Thanks.

EDIT

The original question mentioned 1x65536, but realized that it should be 65536x2

Simplicity
  • 47,404
  • 98
  • 256
  • 385

2 Answers2

2

You could use N = reshape(u, 256, []) and then verify that size(N) is 256 x 256. This syntax for reshape automatically sizes the dimension specified by [] to whatever it needs to be to fit the number of elements in the array.

EDIT: My own attempt at reshaping a random 1 x 65536 matrix into a 256 x 256 matrix did not have a problem with either syntax, so I would suggest you verify that your initial matrix is in fact 1 x 65536 as well.

Engineero
  • 12,340
  • 5
  • 53
  • 75
0

You cannot reshape 65536-by-2 array into 256-by-256 you have "extra" 65536 elements...

try

>> reshape( u, 256, 256 ,[] );
Shai
  • 111,146
  • 38
  • 238
  • 371