How can I make my table aligned?

1 次查看(过去 30 天)
Ruten9
Ruten9 2015-10-27
编辑: Jan 2015-10-27
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 个评论
Jan
Jan 2015-10-27
编辑:Jan 2015-10-27
Please do not force us to open strange looking links to understand your problem. You can post text and images in this forum directly.
Do you see, that your code is not readable? Edit it and use the "{} Code" button.
Stephen23
Stephen23 2015-10-27
编辑:Stephen23 2015-10-27
Click on links to dodgy websites? Why would I do that?

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by