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 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by