How can I make my table aligned?
1 view (last 30 days)
Show older comments
When I run this code:
%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])';
frewind(grades);
%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} ;
fclose(grades);
%Part C (Means)
%what does enlarge matrix G by appndation mean/
clc;
studentmean = mean(G')';
exammean = mean(G);
overallmean = (mean(exammean) + mean(studentmean))./2;
R = [G studentmean];
%Part D (Table)
clc;
P = flipud(sortrows(R,4)) ;
[AVE,is] = sort(R(:,4),'descend');
NI = N(is);
IS = I(is);
lol =NI';
lol2= IS';
GI = [NI IS];
gprime = GI';
O= (num2cell(P));
L= [NI,IS,O]';
Lfake = [NI,O]';
%Lgy = [NI
%B= flipud(sortrows(L',6));
clc;
table = fopen('rec0506d.dat','w') ;
fprintf(table,'Name netID E1 E2 E2| AVE \n ---------------------------------------------------------------------------------\n')
s= '%s %s %-1.0f %-1.0f %-1.0f| %6.2f \n';
fprintf(table,s, L{:})
%31.0f %7.0f %7.0f| %15.2f \n
%s= '%s \n %s ';
%fprintf(table,s,gprime{:})
fprintf(table,'--------------------------------------------------------------------------------\n')
fprintf(table,' exam_AV = %6.2f %6.2f %6.2f | %6.2f \n', [exammean,overallmean])
fclose(table)
type rec0506d.dat
I end up with this: https://gyazo.com/2bed3c42308dede165e4761b6740d651
it's the second column that throws everything off. How can I resolve this?
2 Comments
Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!