필터 지우기
필터 지우기

Display array values side by side

조회 수: 10 (최근 30일)
Shannon Cherry
Shannon Cherry 2018년 8월 7일
답변: Star Strider 2018년 8월 7일
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

채택된 답변

Star Strider
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개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by