필터 지우기
필터 지우기

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