1

Suppose I have four vectors x,y,z,c

How do I get matlab to display it using fprintf in a table form with titles above each column like "title 1" and the x column below it.

1 Answer 1

1

Here is a short example to get you going. I suggest reading the docs about fprintf also.

clear
clc

%// Dummy data
x = .1:.1:1;
y = 2:2:20;
z = x+y;

%// Concatenate data
A = [x; y ; z];

%// Open file to write
fileID = fopen('MyTable.txt','w');

%// Select format for text and numbers
fprintf(fileID,'%6s %6s %6s\n','x','y','z');
fprintf(fileID,'%.2f \t %.2f \t %.2f\n',A);
fclose(fileID);

Checking what MyTable looks like:

type ('MyTable.txt');



    x      y      z
0.10     2.00    2.10
0.20     4.00    4.20
0.30     6.00    6.30
0.40     8.00    8.40
0.50     10.00   10.50
0.60     12.00   12.60
0.70     14.00   14.70
0.80     16.00   16.80
0.90     18.00   18.90
1.00     20.00   21.00

Hope that helps!

Sign up to request clarification or add additional context in comments.

1 Comment

What if a \t is not enough? Eg: Too much digits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.