Converting column vectors into 128x128 matrix to obtain a picture

2 visualizaciones (últimos 30 días)
Hello I am pretty new to Matlab, and I am trying to convert my data file into an 128x128 matrix in order to display an image. So, in my file I have 3 columns with 16384 numeric values in each of them, and I need to have 128x128x3 matrix, like a format of image. I was trying method reshape, but it did not work for me, I am getting an error such
Error using reshape
To RESHAPE the number of elements must not change.
Here is my code
fileID = fopen('out.txt','r');
formatSpec = '%d';
A = fscanf(fileID,formatSpec);
B = reshape (A,128,128);
Please suggest what would be the best solution for this problem.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Mzo. de 2018
Editada: Walter Roberson el 4 de Mzo. de 2018
B = reshape(A,64,128,3);
Note: probably you want
B = uint8( reshape(A,64,128,3) );
It is possible you want A,128,64,3 instead of A,64,128,3 -- you will need to try both versions.
  3 comentarios
Walter Roberson
Walter Roberson el 4 de Mzo. de 2018
I am not sure now why my earlier calculation had been that you needed 64*128 instead 128*128
Danila Frolov
Danila Frolov el 5 de Mzo. de 2018
Thank you @Roger Stafford and Walter Roberson, that solved my problem.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by