Filter löschen
Filter löschen

making integers in a column

1 Ansicht (letzte 30 Tage)
Raviteja
Raviteja am 29 Jan. 2012
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?

Antworten (1)

Image Analyst
Image Analyst am 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

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by