convert 3D to 2D?

1 visualización (últimos 30 días)
lafnath p
lafnath p el 19 de Oct. de 2016
Respondida: Walter Roberson el 20 de Oct. de 2016
Help me to convert 3d matrix (consider x-y-z plane) to x times 2d matrix (y-z). Then I want to write this output to a file as ...(x1y1z1), (x2y2z2),(x3y3z3) and so on; (xyz)=value of x-y-z position in matrix
  5 comentarios
Steven Lord
Steven Lord el 19 de Oct. de 2016
To ask a more specific version of Walter's question:
A = reshape(1:24, [2 3 4])
If you were to write A to a file in the way you want to write your real 3-D array, what would the EXACT contents of the file be? Be specific: I want to see exactly how you'd arrange the numbers 1 through 24 in the file and I would like to see whatever else you add beyond just the numbers in A.
lafnath p
lafnath p el 20 de Oct. de 2016
Editada: lafnath p el 20 de Oct. de 2016
If X-,Y-,Z-axis is 2, 3, 4 respectively then .I need to write the matrix as:
g(1,1,1),g(1,2,1),g(1,3,1),g(1,1,2),g(1,2,2),g(1,3,2),g(1,1,3),g(1,2,3),g(1,3,3),g(1,1,4),g(1,2,4),g(1,3,4) nextline(Complete one xplane) g(2,1,1),g(2,2,1),g(2,3,1),g(2,1,2),g(2,2,2),g(2,3,2),g(2,1,3),g(2,2,3),g(2,3,3),g(2,1,4),g(2,2,4),g(2,3,4) nextline(2nd xplane..and so on...)
But in actual case x-y-z is very large .

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Oct. de 2016
ps = size(g,2)*size(g,3)
fmt = [repmat('%g,', 1, ps-1), '%g\n'];
fprintf(fmt, permute(g, [2 3 1]));

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by