Borrar filtros
Borrar filtros

Display array values side by side

10 visualizaciones (últimos 30 días)
Shannon Cherry
Shannon Cherry el 7 de Ag. de 2018
Respondida: Star Strider el 7 de Ag. de 2018
I have two arrays 'real' and 'imag' and this needs to be copied to a text file side by side. I tried the below as per Displaying data side by side
real = 1:5;
imag = 6:10;
fileID = fopen('data.txt','w');
fprintf(fileID,'%8d\t %8d\n',[real, imag]');
fclose(fileID);
This doesn't seem to work as it displays:
1 2
3 4
5 6
7 8
9 10
Expected output:
1 6
2 7
3 8
4 9
5 10

Respuesta aceptada

Star Strider
Star Strider el 7 de Ag. de 2018
Force ‘real’ and ‘imag’ to become column vectors first:
fprintf(fileID,'%8d\t %8d\n',[real(:), imag(:)]')
or vertically concatenate them:
fprintf(fileID,'%8d\t %8d\n',[real; imag])
Both will produce your desired result.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type 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