I cant get fprintf to work

1 回表示 (過去 30 日間)
Not_sharpest_tool.mat
Not_sharpest_tool.mat 2019 年 7 月 23 日
回答済み: Raj 2019 年 7 月 23 日
I just want to display the values. For some reason it wont display some of them and the ones that are displayed are in scientific notation. How can I correct my code so that all values are displayed and how can I make the numbers be in regular notation (Ex: 4.66 instead of 4.660000e+1)
%% Loading the data
clc
load carbig;
%% Exploring two variables
%Miles Per Galon
a= min(MPG);
b= max(MPG);
c= mode(MPG);
d= nanmean(MPG);
fprintf('Minimum MPG is %s, Maximum MPG is %s, Mode MPG is %s and Mean MPG is %s\n',a,b,c,d)

採用された回答

madhan ravi
madhan ravi 2019 年 7 月 23 日
Use %.2f instead of %s

その他の回答 (1 件)

Raj
Raj 2019 年 7 月 23 日
Since you have not shared your mat file, I am assuming a,b,c,d are numbers. In that case, why are you using %s (which is for string data type) to display them? You should use %f to display decimal numbers in 'regular notation' as you have asked for.
See details here:

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by