making integers in a column

1 回表示 (過去 30 日間)
Raviteja
Raviteja 2012 年 1 月 29 日
In a program I have following result for 'Check' variable
>>Check=[testing_ind' ldaClass All_data(testing_ind,:)];
>>Check =
9.0000 1.0000 1.4000 0.2000
32.0000 1.0000 1.5000 0.4000
33.0000 1.0000 1.5000 0.1000
34.0000 0.0000 1.4000 0.2000
35.0000 0.0000 1.5000 0.2000
But I want the output like this
>>Check =
9 1 1.4000 0.2000
32 1 1.5000 0.4000
33 1 1.5000 0.1000
34 0 1.4000 0.2000
35 0 1.5000 0.2000
How to do this?

回答 (1 件)

Image Analyst
Image Analyst 2012 年 1 月 29 日
Use fprintf() to specify how many decimal places you want when you print stuff out.
Check =[...
9.0000 1.0000 1.4000 0.2000
32.0000 1.0000 1.5000 0.4000
33.0000 1.0000 1.5000 0.1000
34.0000 0.0000 1.4000 0.2000
35.0000 0.0000 1.5000 0.2000]
for k = 1 : size(Check, 1)
fprintf('%4d %4d %.4f %.4f\n', Check(k,1),Check(k,2),Check(k,3),Check(k,4));
end
Results in command window:
9 1 1.4000 0.2000
32 1 1.5000 0.4000
33 1 1.5000 0.1000
34 0 1.4000 0.2000
35 0 1.5000 0.2000

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by