Display array values side by side

16 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 7 Aug 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.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!