help me! about Matlab

Thread Starter

masteroind

Joined May 14, 2011
1
I have a problem with this file that I have wrote it

clear
fid=fopen ('dusss.txt');
A=fscanf(fid,'%g%g%g%g',[4 inf]);
fclose(fid);
clc
B=load('dusss.txt');

for i=1:17;
Result(i,1)=B(i,2)+B(i,3)+B(i,4);

if Result(i,1)>79
G(i,1)=A;
elseif Result(i,1)>74
G(i,1)=3.5;
elseif Result(i,1)>69
G(i,1)=3;
elseif Result(i,1)>64
G(i,1)=2.5;
elseif Result(i,1)>59
G(i,1)=2;
elseif Result(i,1)>54
G(i,1)=1.5;
elseif Result(i,1)>49
G(i,1)=1;
else
G(i,1)=0;
end


end
S=[B Result G];
disp(' code F.test S.test Final test total Grade')
disp(' 30% 15% 50% 100%')
disp(S)


When I run this file why the result be like this

code F.test S.test Final test total Grade
30% 15% 50% 100%
1.0e+007 *
4.9024 0.0000 0.0000 0.0000 0.0000 0.0000
4.9026 0.0000 0.0000 0.0000 0.0000 0.0000
4.9029 0.0000 0.0000 0.0000 0.0000 0.0000
4.9037 0.0000 0.0000 0.0000 0.0000 0.0000
4.9037 0.0000 0.0000 0.0000 0.0000 0.0000
4.9048 0.0000 0.0000 0.0000 0.0000 0.0000
4.9075 0.0000 0.0000 0.0000 0.0000 0.0000
5.0013 0.0000 0.0000 0.0000 0.0000 0.0000
5.0015 0.0000 0.0000 0.0000 0.0000 0.0000
5.0017 0.0000 0.0000 0.0000 0.0000 0.0000
5.0018 0.0000 0.0000 0.0000 0.0000 0.0000
5.0025 0.0000 0.0000 0.0000 0.0000 0.0000
5.0032 0.0000 0.0000 0.0000 0.0000 0.0000
5.0033 0.0000 0.0000 0.0000 0.0000 0.0000
5.0034 0.0000 0.0000 0.0000 0.0000 0.0000
5.0053 0.0000 0.0000 0.0000 0.0000 0.0000
5.0059 0.0000 0.0000 0.0000 0.0000 0.0000


I want it be like this

code F.test S.test Final test Total Grade
30% 15% 50% 100%
49024226 30 12 44 86 4
49026308 32 10 8 50 1
49028593 25 5 40 70 3
49036559 23 7 33 63 2
49037376 31 7 18 56 1.5
49047654 25 3 35 63 2
49074579 34 7 20 61 2
50012883 31 7 34 72 3
50014643 34 7 15 56 1.5
50017453 35 8 7 50 1
50018263 28 7 35 70 3
50024832 34 9 27 70 3
50032381 32 7 21 60 2
50033242 33 7 13 53 1
50034285 27 5 40 72 3
50053497 35 9 18 62 2
50058889 29 7 30 66 2.5


I need you to fix this one as soon as you can, thank you every much
 

steveb

Joined Jul 3, 2008
2,436
I have a problem with this file that I have wrote it

Rich (BB code):
clear
fid=fopen ('dusss.txt');
A=fscanf(fid,'%g%g%g%g',[4 inf]);
fclose(fid);
clc
B=load('dusss.txt');
 
for i=1:17; 
    Result(i,1)=B(i,2)+B(i,3)+B(i,4);
    
  if Result(i,1)>79
       G(i,1)=A;
    elseif Result(i,1)>74
       G(i,1)=3.5;
    elseif Result(i,1)>69
        G(i,1)=3;
    elseif Result(i,1)>64
        G(i,1)=2.5;
    elseif Result(i,1)>59
        G(i,1)=2;
    elseif Result(i,1)>54
        G(i,1)=1.5;
    elseif Result(i,1)>49
        G(i,1)=1;
    else
        G(i,1)=0;       
    end
   
   
end
S=[B Result G];
disp('    code         F.test       S.test      Final test     total          Grade')
disp('                      30%         15%         50%        100%')
disp(S)

When I run this file why the result be like this

Rich (BB code):
   code           F.test       S.test     Final test    total       Grade
                      30%         15%         50%        100%
  1.0e+007 *
    4.9024    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9026    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9029    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9037    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9037    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9048    0.0000    0.0000    0.0000    0.0000    0.0000
    4.9075    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0013    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0015    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0017    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0018    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0025    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0032    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0033    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0034    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0053    0.0000    0.0000    0.0000    0.0000    0.0000
    5.0059    0.0000    0.0000    0.0000    0.0000    0.0000
I want it be like this

Rich (BB code):
      code            F.test      S.test   Final test  Total       Grade  
                          30%        15%       50%      100%   
    49024226          30          12          44          86           4  
    49026308          32          10           8          50           1
    49028593          25           5          40          70           3
    49036559          23           7          33          63           2
    49037376          31           7          18          56          1.5
    49047654          25           3          35          63           2
    49074579          34           7          20          61           2
    50012883          31           7          34          72           3
    50014643          34           7          15          56          1.5
    50017453          35           8           7          50            1
    50018263          28           7          35          70            3
    50024832          34           9          27          70            3
    50032381          32           7          21          60            2
    50033242          33           7          13          53            1
    50034285          27           5          40          72            3
    50053497          35           9          18          62            2
    50058889          29           7          30          66           2.5
I need you to fix this one as soon as you can, thank you every much
Look up help on the following commands: format, int8, int16, int32, uint8, uint16 and uint32.

You basically have an issue with formatting of the displayed output.

if you use the "format long g" command you will allow the full double precision values to be displayed, rather than the truncated values you see. Also, your first column appears to be an integer value (I'm not sure), and if so, you may want to convert the value to integer before displaying it.
 

steveb

Joined Jul 3, 2008
2,436
Note, you may also want to look into the sprintf and fprintf commands which allow printing to files and to strings with better formatting control. Just dumping an array to the screen is somewhat limited. The issue is that your first column has so many numbers, and the other columns don't.
 
Top