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.
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!