Displaying data side by side using fprintf
23 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ian Barker
am 21 Mär. 2013
Kommentiert: the cyclist
am 22 Okt. 2018
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.
0 Kommentare
Akzeptierte Antwort
the cyclist
am 21 Mär. 2013
One way:
fprintf('%8.2f %8.3f\n', [velocity,distance]')
4 Kommentare
the cyclist
am 22 Okt. 2018
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.)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!