All 3 entries tagged Matlab

View all 7 entries tagged Matlab on Warwick Blogs | View entries tagged Matlab at Technorati | There are no images tagged Matlab on this blog

September 22, 2010

Where did all that time go!

In about a week's time, I'll be flying back to the UK! 

Almost time to submit report and poster. Second draft of report is finished, poster is unfinished yet. Hoping to get everything done by next Monday.

Of course, I made a rather good prediction - with the CSC resources going offline far too often in the past month, I've just barely managed to scrape by with the simulations I need. I've even resorted to running some on my 5 year old desktop at home!

Note to self: Think further ahead when running simulations - get the parameters right! I now have data which are not very compatible with each other, sigh. Wouldn't be that bad if I had the resources to get my simulations re-run quickly!


Turns out after I posted the last entry I had the chance to speak to a friend who's working with the Singapore Land Transport Agency (LTA), and so I had a chance to ask him about Distance-based fares.

"So, how did you guys come up with the 66% figure? Based on real data?"

"Yes, that's right."

"Hmm, alright. Is it also true then that the fare decreases are mostly less than 10 cents while the increases are mostly greater than 10 cents?"

"Hmm, yes, you could say that."

"So there's an overall increase in revenue?"


Before anyone misunderstands, I'm not criticising the increase in revenue, after all, inflation is (somewhat) a part of life. I just wish to point out how a figure being thrown about can be rather meaningless, in this case the two-thirds having lower fares being repeatedly mentioned. I have no access to the real data to verify if it is true in any case. (Britons, rejoice that you actually have the Freedom of Information Act!)

In any case, I've done my fair bit in abusing the new fare system. I had to take a bus ride back home, where I was faced with the option of getting off and walking 7 minutes home or changing to a feeder bus service right to my doorstep. Under the old fare system, the latter would cost me an extra 25 cents. It cost me only 8 cents now.

August 05, 2010

Simple simulation – Am I being naive?

Saw this sometime last week:

I will not rehash the main points, but the idea that popped up in my mind was, the patients will not necessarily all have the same mortality rate so what happens if we have a population of patients with different mortality rates?

I thought of possible ways to simulate this, but did not sit down to try it till today. Took me a while to figure out the relevant MATLAB commands and to structure it. Thanks goes to Leonard who gave me some ideas on how to write the code.

Simple assumptions of population of patients:

  • 10% have 6% mortality rate (difficult case)
  • 25% have 3% mortality rate (moderate case)
  • 65% have 1% mortality rate (simple case)

And then each hospital has a certain number of patients, which is fixed. How do the hospitals do?

For size 5:

Value    Count   Percent
     0     2653     26.53%
     1     5081     50.81%
     2     1946     19.46%
     3      301      3.01%
     4       19      0.19%

For size 10:

Value    Count   Percent
     0      541      5.41%
     1     2118     21.18%
     2     3224     32.24%
     3     2488     24.88%
     4     1188     11.88%
     5      370      3.70%
     6       67      0.67%
     7        4      0.04%

I did 10000 realizations on both.

Would it be fair then to say that a hospital with low number of patients can easily get a high mortality rate by just being unlucky?

MATLAB code for those interested below. I may have missed out something as I finished this in less than an hour!


function AAAsim(nRlz,sz)
% Simulation of AAA patients.
% Assume 2% mortality in general
% 3 Classes of Patients:
% 10% chance of patient with 6% mortality
% 25% chance of patient with 3% mortality
% 65% chance of patient with 1% mortality
% Assume each hospital has sz patients

n = nRlz * sz; %population size

index = randperm(n); % Randomly order patients

for i=1:nRlz
   a = sz*(nRlz - 1) + 1;
   b = sz*(nRlz);
   sample = index(a:b);
   sam_death = 0;
   for j=1:sz
       pt = sample(j);
       if(pt <=(0.1*n));
           prob = 0.6;
       elseif(pt > (0.1*n) && pt <=(0.35*n));
           prob = 0.3;
       else(pt > (0.35*n));
           prob = 0.1;
       ptdoa = binornd(1,prob); % Returns 0 if alive, 1 if dead
       sam_death = sam_death + ptdoa;
   deaths(i)= sam_death;
   fprintf('Iteration number %d completed.\n',i);

July 13, 2010

Linux tips and tricks

From Dr Nichols on script files:

Make a script file, .sh
must begin "#!/bin/bash"
Give it execute permissions
chmod +x (Important! If not script will not run!)

and be sure to re-direct all output to a log file

Then when you run the script, put it in the background

  ./ &

Here is my file


matlab -nojvm -nodisplay < doit.m > test2.log 2>&1

Also, how to start up matlab and add path to matlab every login

Edit ./.bashrc, using say, emacs i.e. at the prompt type "emacs ./.bashrc"

Add the following lines:

module add matlab

for example, given that I put the spm8 files into /home/spm8/

Useful commands to view log files are cat, tail etc.

September 2023

Mo Tu We Th Fr Sa Su
Aug |  Today  |
            1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30   

Search this blog



Most recent comments

  • Thanks a lot! That does seem to work better! by on this entry
  • You don't need to cat /dev/null into a file to empty it, you can just use > For example: me@mine:/tm… by Mike Willis on this entry

Blog archive

RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder