My output did not display in command windows when using script
조회 수: 24 (최근 30일)
이전 댓글 표시
hello, I have a problem where my output did not display in command windows when i have run in script ,what should i do? my coding can run but did not display in command windows.
This below my coding
fid = fopen('abc.txt','w');
vol=zeros(6,4);
Percentage=zeros(6,4);
Vact= [31.06300,40.29600,49.52700,58.75800;
6.209400,8.057700,9.904700,11.75130;
0.306610,0.401110,0.494380,0.587210;
0.073430,0.098860,0.122920,0.146530;
0.039958,0.055665,0.069856,0.083571;
0.026436,0.038378,0.048629,0.058391];
P = [0.01,0.05,1,4,7,10];
T = [673.15,873.15,1073.15,1273.15];
for i=1:6
for j=1:4
vol(i,j) = ((0.000461631).*T(j))./P(i);
end
end
% Calculate %error
for i=1:6
for j=1:4
Percentage(i,j) = 100.0*(vol(i,j)-Vact(i,j))/Vact(i,j);
end
end
% Table header estimated z
fprintf(fid,'Estimated z');
fprintf(fid,'\n 2 4 6\n');
fprintf(fid,' ---------------------------------\n');
% Print estimated z table
for i=1:6
fprintf(fid,' | %6.2f | %6.5f %6.5f %6.5f %6.5f | \n',P(i), vol(i,1), vol(i,2), vol(i,3), vol(i,4));
end
% Table header % error
fprintf(fid,'\nEstimated errors');
fprintf(fid,'\n 2 4 6\n');
fprintf(fid,' ---------------------------------\n');
% Percentage error table
for i=1:6
fprintf(fid,' | %6.2f | %6.2f %6.2f %6.2f %6.2f | \n',P(i), Percentage(i,1), Percentage(i,2), Percentage(i,3), Percentage(i,4));
end
fclose(fid);
This below showed my screen that command windows give me only the name of my file
댓글 수: 1
Stephen23
2020년 6월 25일
Your code seems to be behaving as expected: there appears to be no commands that would print to the command window and you have semi-colons at the end of each line. Why do you expect something to be printed in the command window?
Tip: when opening a text file you should use the t option, e.g.:
fid = fopen('abc.txt','wt');
답변 (1개)
the cyclist
2020년 6월 25일
편집: the cyclist
2020년 6월 25일
The syntax you used,
fprintf(fid,...)
is explicitly for writing to files. Use
fprintf(...) % without "fid" argument
to write to the command window instead.
댓글 수: 1
Adam Danz
2020년 6월 25일
+1
The first input can also be 1 to print to the command window.
fprintf(1, ...)
or 2 to print to the command window in red
fprintf(2, ...)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!