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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by