필터 지우기
필터 지우기

Save data to file

조회 수: 1 (최근 30일)
monkey_matlab
monkey_matlab 2015년 10월 27일
답변: Star Strider 2015년 10월 27일
Hello,
In my code below, I am having a problem saving the matrix A properly to a file. The saved data is getting mixed up and does not correspond to the matrix A. Can you help me save the data properly?
a = (0.5)*rand(20,1);
b = (0.5)*rand(20,1);
c = (0.5)*rand(20,1);
d = (0.5)*rand(20,1);
e = (0.5)*rand(20,1);
A = [a b c d e];
fileID = fopen('check.txt','w');
fprintf(fileID,'%6s %6s %6s %6s %6s\r\n','a','b', 'c', 'd', 'e');
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A);
fclose(fileID);

채택된 답변

Star Strider
Star Strider 2015년 10월 27일
Transpose ‘A’ and it should work:
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A.');
or if ‘A’ will always be real:
fprintf(fileID,'%6.5f %6.5f %6.5f %6.5f %6.5f\r\n',A');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by