Two questions in one day, I must be pretty bad at this. Anyways after getting past my first problem I now have to display two arrays side by side like a table. Normally I'd just combine them and print them out at once or something but the different columns have to be displayed with different significant figures.
I've tried this:
fprintf('%.2f %.3f\n', velocity,distance)
but it turns out way wrong.
The two vectors are:
velocity
170
290
-130
-70
-185
-220
200
290
270
200
300
-30
650
150
500
920
450
500
500
960
500
850
800
1090
and distance
0.0320
0.0340
0.2140
0.2630
0.2750
0.2750
0.4500
0.5000
0.5000
0.6300
0.8000
0.9000
0.9000
0.9000
0.9000
1.0000
1.1000
1.1000
1.4000
1.7000
2.0000
2.0000
2.0000
2.0000
All I need is a way to get them next to each other. I can figure out the significant figures and spacing myself.
Thanks alot.

 채택된 답변

the cyclist
the cyclist 2013년 3월 21일

10 개 추천

One way:
fprintf('%8.2f %8.3f\n', [velocity,distance]')

댓글 수: 4

Ian Barker
Ian Barker 2013년 3월 21일
Ah that apostrophe at the end seems to do the trick. What does that even do exactly?
Anyways thanks a lot for your help.
It's taking the transpose of the matrix.
doc transpose
for details.
Shahbaz BHATI
Shahbaz BHATI 2018년 10월 22일
is there any way i can add serial numbers to the same output?
If your serial number is purely numeric, then you can just add another column:
velocity = [2.011;3.012;4.013];
distance = [2.001;3.002;4.003];
sn = [487969816; 487969876; 487969873];
sprintf('%10d %8.2f %8.3f\n', [sn,velocity,distance]')
If not (e.g. if your serial number is something like SN4876), then you'll need a different approach. I suggest you open a new question with a bit more detail and a small sample of what your input data look like. (If you link that new question here, I'll try to look for it.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

2013년 3월 21일

댓글:

2018년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by