what is wrong with fprintf

2 ビュー (過去 30 日間)
Tor Fredrik Hove
Tor Fredrik Hove 2011 年 10 月 19 日
why does not this function give the full text in fprintf:
function printem(a,b)
fprintf('the first number is %.lf and the second is %.lf\n',a,b)
end
what is displayed in matlab is
>> printem(3,5) the first number is>>

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 10 月 19 日
>> a=rand(4,1)
a =
0.67874
0.75774
0.74313
0.39223
>> b = randi(9,4,1)
b =
6
2
7
1
>> fprintf('the first number is %f and the second is %f\n',[a,b]')
the first number is 0.678735 and the second is 6.000000
the first number is 0.757740 and the second is 2.000000
the first number is 0.743132 and the second is 7.000000
the first number is 0.392227 and the second is 1.000000
>>
more
>> printem = @(a,b)fprintf('the first number is %.1f and the second is %.1f\n',[a,b]')
>> printem(3,5)
the first number is 3.0 and the second is 5.0
>>

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 10 月 19 日
You appear to have used %.lf (lower-case L) instead of %.1f (digit one)

Harry MacDowel
Harry MacDowel 2011 年 10 月 19 日
Try this
fprintf('the first number is %0.1f and the second is %0.1f\n',a,b)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by