Pages

Tuesday 17 May 2016

A Random Walk

It is fascinating to see the use of the word 'random' and its resemblance to one of the most basic ingredients in some computer algorithms. One may ask what is it that makes something random?

- "So you just made a random deal?"
- "Students were randomly chosen to take part in a drama."
- "He figured out that he still had an hour to his departure, so he went for a random walk."

Monday 9 May 2016

Matlab script for checking and deleting folders

Just putting this simple but extremely useful matlab script for my future self and anyone trying to handle folders using matlab. This script checks all the sub directory within the starting directory and then deletes the one that do not satisfy a given criteria. In my case this was the number of image samples within a folder.

% script for deleting folders with less than a certain number of files
close all
clear all
clc

% count the number of png files
D = dir(' ');


numFoldersOrFiles = size(D, 1);

thresholdFiles = 30;

% skipping the first two which are just . and ..
for i = 3: numFoldersOrFiles
    
    if D(i).isdir
        
        Ds = dir([D(i).name '\*.png']);
        numFiles = size(Ds, 1) / 3;
        if numFiles < thresholdFiles
            
            rmdir(D(i).name, 's');
            
        end
    end
end


% all done :)