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 CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by