My output did not display in command windows when using script
22 次查看(过去 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!