5 views (last 30 days)

I have 65536 real data points saved from an image. I have used reshape command to make square matrix. But result I am getting is 16 by 256 . Why is it so? Can I reconstruct the image ??

a = load('fname.txt');

y=reshape (a,256,256)

but instead of 256 by 256 it is showing 16 by 256

Ahmed A. Selman
on 28 Jun 2013

Dear sudipta,

I have downloaded your data file, and went like

a=load('1372387722318.txt');

y=reshape (a,256,256);

whos

Name Size Bytes Class Attributes

a 65536x1 524288 double

y 256x256 524288 double

and everything is just fine to me. So, the only possible error is that: you have another file with a name (fname.txt) in your directory which is not the same file you uploaded (1372387722318.txt). Check this out and I'm pretty sure you'll have it working.

Regards

Jan
on 28 Jun 2013

Edited: Jan
on 28 Jun 2013

It is impossible that Matlab's reshape changes the number of elements of the processed array. Therefore I'm convinced, that something completely different went wrong:

- You do not read the file your assume to read
- "It is showing 16 by 256" does not explain, how you check the size. Perhaps the bug is found in your method to obtain the array size.
- You do not use Matlab's reshape but a user-defined function. Check this by:

which reshape -all

Anand
on 27 Jun 2013

This is what you should do for an image with 65536 pixels that you want to make square:

nelem = numel(A);

side = sqrt(nelem);

Areshaped = reshape(A,side,side);

David Sanchez
on 28 Jun 2013

To reshape/resize an image, use:

imresize

Type:

help imresize

Or

doc imresize

for all the information needed to handle the issue.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157334

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157334

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157383

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157383

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157400

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157400

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157401

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157401

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157422

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/80484-reshape-array-for-256-by-256-matrix-showing-16-by-256#comment_157422

Sign in to comment.