How can I make the spacing in a table more consistent? Also, how could i rearrange the table's names to match the one in part 2d?

4 views (last 30 days)
%Part A (matrix G)
clear all; clc;
type rec0506c.dat %displays content in file
grades = fopen('rec0506c.dat','r');
fgetl(grades); fgetl(grades);
G = fscanf(grades, '%*s%*s%f%f%f%*s \n',[3,7])';
%Part B (textscan)
fgetl(grades); fgetl(grades);
C= textscan(grades, '%s %s %f %f %f %s' );
A= cell2mat(C(3:5)) ;
N = C{1};
I = C{2} ;
%Part C (Means)
studentmean = mean(G')';
exammean = mean(G);
overallmean = (mean(exammean) + mean(studentmean))./2;
R = [G studentmean]
%Part D (Table)
P = flipud(sortrows(R,4))
NI = [N I];
O= (num2cell(P));
L= [NI O]';
bottom = [exammean,overallmean]
table = fopen('rec0506d.dat','w') ;
fprintf(table,'Name netID E1 E2 E2| AVE \n -----------------------------------------------------\n')
fprintf(table,'%s %s%13.0f%13.0f%13.0f|%13.2f \n',L{:})
fprintf(table,'exam_AV = %2.2f %2.2f %2.2f | %2.2f \n', [exammean,overallmean])
type rec0506d.dat
I want my graph to look like the one in part2d.
When I run my code, I end up with a very demented table:

Answers (1)

Ingrid on 26 Oct 2015
have you tried to use the tab delimiter in the fprintf statement as suggested here :

Community Treasure Hunt

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

Start Hunting!

Translated by