Display array values side by side
15 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2018-8-7
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!