Message Boards Message Boards

0
|
3860 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

[?] Get proper format of a matrix , avoid matrix values with "Null" added?

Posted 6 years ago

I fill a matrix “Estimate” in a module (See code snippet}. I follow the filling of the matrix with “TracePrint[Estimate[[j,i]]” and the matrix is filling nicely with expected values. But somehow in the “Official Output” ( so to speak) the text “Null” is added to alle values ?

What’s happening here ? And how to avoid it ?

Best Regards, Chiel Geeraert

In[3]:= Module[{i, j, k, Nrandom, procenttabel, sampleSize, sample, 
  Estimate},
 procenttabel = {0.02, 0.05, 0.10, 0.2};
 Estimate = Table[0, {i, 1, Length[procenttabel]}, {j, 1, 5}];
 Nrandom = 800;
 j = 1;
 While[j <= Length[procenttabel],
    sampleSize = procenttabel[[j]]* Nrandom;
    i = 1;
    While[i <= 5,
          sample = Table[RandomInteger[{1, 800}], {k, 1, sampleSize}];
          Estimate[[j, i]] = N[(sampleSize + 1)/sampleSize* Max[sample] - 1, 3];
          TracePrint[Estimate[[j, i]]];
          i++
          ]
        j++
    ]
  Estimate]

During evaluation of In[3]:=  {{799.063,793.75,820.313,824.563,840.5},{810.8,800.55,819.,813.875,816.95},{806.975,809.,800.9,803.938,804.95},{799.975,804.,799.975,800.981,804.}}[[4,5]]

During evaluation of In[3]:=  804.

Out[3]= {{799.063 Null, 793.75 Null, 820.313 Null, 824.563 Null, 
  840.5 Null}, {810.8 Null, 800.55 Null, 819. Null, 813.875 Null, 
  816.95 Null}, {806.975 Null, 809. Null, 800.9 Null, 803.938 Null, 
  804.95 Null}, {799.975 Null, 804. Null, 799.975 Null, 800.981 Null, 
  804. Null}}
POSTED BY: Chiel Geeraert
Posted 6 years ago

I found it : forgot a semicolon in the code

While[i <= 5,

      sample = Table[RandomInteger[{1, 800}], {k, 1, sampleSize}];
      Estimate[[j, i]] = 
  N[(sampleSize + 1)/sampleSize Max[sample] - 1, 3];
      TracePrint[Estimate[[j, i]]];
      i++
      ];

j++ ] <--------------------------------------------- There ! Forgot it and you get {234' Null} With semicolon neatly {234} Estimate ]

POSTED BY: Chiel Geeraert
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract