making integers in a column
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Image Analyst
on 29 Jan 2012
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
0 Comments
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!