以下是我的代码摘录,我使用fprintf将结果写入命令窗口:
...
hold off;
X_H2S = (F_H2S_0-F_H2S)/F_H2S_0;
X_COS = (F_COS_0-F_COS)/F_COS_0;
X_CS2 = (F_CS2_0-F_CS2)/F_CS2_0;
plot(W,X_H2S,W,X_COS,W,X_CS2)
fprintf('\nFinal conversions (percent):\n\t\tH2S: %f\n\t\tCOS: %f\n\t\tCS2: %f\n\n',100*X_H2S(size(X_H2S)),100*X_COS(size(X_COS)),100*X_CS2(size(X_CS2)))
fprintf('Pressure drop: %f to %f (%f percent)',P_0,P(size(P)),100*(P_0-P)/P_0)
format longG
%format compact
length = size(fs, 2);
...
由于某种原因,它输出如下:
Final conversions (percent):
H2S: 24.838056
COS: 0.000000
CS2: 99.997968
Final conversions (percent):
H2S: 0.000000
COS: 98.985525
CS2: 0.000000
Pressure drop: 129099.000000 to 128217.024848 (129099.000000 percent)Pressure drop: 0.000000 to 0.000000 (0.000000 percent)Pressure drop: 0.000000 to 0.000000 (0.000000 percent)Pressure drop: 0.000000 to 0.000002 (0.000003 percent)Pressure drop: 0.000005 to 0.000020 (0.000034 percent)Pressure drop: 0.000049 to 0.000196 (0.000343 percent)Pressure drop: 0.000490 to 0.001555 (0.002621 percent)Pressure drop: 0.003687 to 0.007620 (0.011556 percent)Pressure drop: 0.015495 to 0.019436 (0.030585 percent)Pressure drop: 0.041755 to 0.052945 (0.064154 percent)Pressure drop: 0.081088 to 0.098064 (0.115084 percent)Pressure drop: 0.132146 to 0.149250 (0.166397 percent)Pressure drop: 0.183585 to 0.200973 (0.218403 percent)Pressure drop: 0.235875 to 0.253389 (0.270943 percent)Pressure drop: 0.288536 to 0.310239 (0.331999 percent)Pressure drop: 0.353815 to 0.375693 (0.397640 percent)Pressure drop: 0.419669 to 0.445698 (0.471872 percent)Pressure drop: 0.498193 to 0.524642 (0.533730 percent)Pressure drop: 0.542828 to 0.551935 (0.561052 percent)Pressure drop: 0.570178 to 0.579314 (0.596511 percent)Pressure drop: 0.613741 to 0.631004 (0.648300 percent)Pressure drop: 0.665627 to 0.683177 (
我知道为什么以及如何解决它?
答案 0 :(得分:1)
你的论点是向量。如果我这样做:
>> fprintf('Number: %f\n',rand(2,1))
Number: 0.957507
Number: 0.964889
我观察到与你相同的行为。您认为只打印一个的原因是因为您正在调用size
,但是size会返回一个包含数组中行数和列数的1x2数组。
答案 1 :(得分:1)
它取决于您提供给fprintf函数的值。见这个输出:
vec rownumber
[1,] "DYNASTY" "5"
[2,] "EASTENDERS" "2"
[3,] "GET FRESH" "1"
[4,] "SPORT" "4"
[5,] "WORLD CUP" "3"