how does fprintf function work?

8 ビュー (過去 30 日間)
Mahmoud
Mahmoud 2014 年 1 月 10 日
コメント済み: Mahmoud 2014 年 1 月 10 日
I have prepared a code that outputs a string that has a value depends in values result from my code. initially, it works with the following code:
fprintf('Arrhythmia was detected at t= %s \n',t(R_loc(i+1)))
and the output, for example, was: Arrhythmia was detected at t=9.550000e+00
I need the result as : Arrhythmia was detected at t=9.55 (without e+00)
another issue, I used this code:
Heart_Rate = length(R_loc)/(length(t)/fs)*60
fprintf('The heart rate = %s \n' , Heart_Rate)
and the result is : Heart_Rate =
54
The heart rate = 6
Why does this happen?
thanks ..

採用された回答

Image Analyst
Image Analyst 2014 年 1 月 10 日
%s is for strings. For a fractional number, use %f:
fprintf('The heart rate = %.3f\n' , Heart_Rate); % 3 decimal places.
  1 件のコメント
Mahmoud
Mahmoud 2014 年 1 月 10 日
Thank you a lot :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by