Rank: 70552 based on 0 downloads (last 30 days) and 0 file submitted
photo

none

E-mail

Personal Profile:

 

Watch this Author's files

 

Comments and Ratings by none View all
Updated File Comments Rating
11 Nov 2014 Files Under Folders (fuf) Recursively search for files through directory trees under given folders. Author: Francesco di Pierro

This is a great function, but has a major limitation due to its use of dir.m

str = 'C:\myFolder';

tic;
myFiles1 = fuf(str, 1,'detail');
t1=toc;

tic;
Folder = [str '\']; %can be a relative path
jFile = java.io.File(Folder); %java file object
%Names_Only = cellstr(char(jFile.list)); %cellstr
myFiles2 = arrayfun(@char,jFile.listFiles,'un',0); %cellstr.
t2=toc;

When the data is large in size (eg >1E5 files) or held on a network (eg cloud platform) then dir.m and hence fuf.m will fail. Use the second method to get around this:)

20 Oct 2014 Round off dates and times Rounds off a datenum to the nearest second, minute, hour, day, month or year. Author: Kevin J. Delaney

with the below mod:

function datenum_rounded = datenum_round_off(datenum_in, time_unit_string, direction)
% Rounds off a datenum to the nearest second, minute, hour, whatever.
%
% datenum_rounded = datenum_round_off(datenum_in, time_unit_string)
%
% Inputs:
% datenum_in Date/time in Matlab datenum format
% time_unit_string String like 'minute', 'second', etc.
%
% Output:
% datenum_rounded Input value rounded off

% Kevin J. Delaney
% January 13, 2010
if(nargin<3)
direction = 'default';
end

datenum_rounded = [];

if ~exist('datenum_in', 'var')
help(mfilename);
return
end

if isempty(datenum_in) || ~isnumeric(datenum_in)
errordlg('Input "datenum_in" is empty or non-numeric.', mfilename);
return
end

if ~exist('time_unit_string', 'var') || ...
isempty(time_unit_string) || ...
~ischar(time_unit_string)
errordlg('Input "time_unit_string" is missing, empty or non-char.', ...
mfilename);
return
end

switch lower(time_unit_string)
case {'second', 'seconds', 'sec', 's'}
time_unit = units(1, 'second', 'day');

case {'minute', 'minutes', 'min', 'm'}
time_unit = units(1, 'minute', 'day');

case {'hour', 'hours', 'hr', 'h'}
time_unit = units(1, 'hour', 'day');

case {'day', 'days', 'd'}
time_unit = 1;

case {'month', 'months', 'mon'}
% Break up the input into year, month, day components.
[yr, mon, day, hr, min, sec] = datevec(datenum_in);

% Are we halfway through the month?
datenum_start_of_this_month = datenum(yr, mon, ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
datenum_start_of_next_month = datenum(yr, mon + 1, ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
round_up_to_next_month_syndrome = (datenum_start_of_next_month - datenum_in) < (datenum_in - datenum_start_of_this_month);
boost_vector = zeros(size(datenum_in));
boost_vector(round_up_to_next_month_syndrome) = 1;
datenum_rounded = datenum(yr, mon + boost_vector, ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
return

case {'year', 'years', 'yr'}
% Break up the input into year, month, day components.
[yr, mon, day, hr, min, sec] = datevec(datenum_in);

% Are we halfway through the year?
datenum_start_of_this_year = datenum(yr, ones(size(mon)), ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
datenum_start_of_next_year = datenum(yr + 1, ones(size(mon)), ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
round_up_to_next_year_syndrome = (datenum_start_of_next_year - datenum_in) < (datenum_in - datenum_start_of_this_year);
boost_vector = zeros(size(datenum_in));
boost_vector(round_up_to_next_year_syndrome) = 1;
datenum_rounded = datenum(yr + boost_vector, ones(size(mon)), ones(size(day)), zeros(size(hr)), zeros(size(min)), zeros(size(sec)));
return

otherwise
errordlg(['Unknown time unit: "', time_unit_string, '".'], mfilename);
return
end

if(strcmpi(direction, 'default'))
datenum_rounded = time_unit * round(datenum_in / time_unit);
elseif(strcmpi(direction, 'down'))
datenum_rounded = time_unit * floor(datenum_in / time_unit);
elseif(strcmpi(direction, 'up'))
datenum_rounded = time_unit * ceil(datenum_in / time_unit);
end

end

16 Oct 2014 Use of MongoDB Java Driver A simple example of how to use java driver for mongoDB. Author: Guillaume A.

Could do with better documentation TBH. Professional code though.

%% Specify the connection details
myHost = '149.451.25.123:27017';
myUsername = 'dataviewer';
myPassword = 'BlahBlahBlackSheep';
myDb = 'myTableName';

%% Connect to MongoDB
MongoStart();
m = Mongo([myHost '/' myDb]);
m.authenticate(myUsername, myPassword);
if ~m.isConnected()
error('MongoSample:MongoSample', 'No connection');
end

13 Oct 2014 JSON Parser Parses JSON strings into structures and cells Author: Joel Feenstra

I get the occasional issue:

Warning: Control Character '\%' is not valid. See 'doc sprintf' for control characters valid in the format string.
> In parse_json>parse_string at 151
In parse_json>parse_value at 31
In parse_json>parse_name_value at 128
In parse_json>parse_object at 102
In parse_json>parse_value at 34
In parse_json at 16
In twitty>twitty.parseTwitterResponse at 434
In twitty>twitty.callTwitterAPI at 2014
In twitty>twitty.friendshipsCreate at 1211

23 Oct 2013 export_fig Exports figures nicely to a number of vector & bitmap formats. Author: Oliver Woodford

Long time user of export_fig here. great function -- thanks!

New machine today. 64 bit Windows 8.1, MATLAB 2013B. Latest installation of Ghoscript (9.1) put onto the machine.

A problem occurs with the function ghostscript.m

On executing the code in this m file: check_gs_path(path) a zero is returned.

This causes the software to ask where the location of the ghostscript executable is -- i point it to the correct dir and it fails to find it.

Thus I have had to hard code in

path = 'C:\Program Files\gs\gs9.10\bin\gswin64c.exe';

before check_gs_path(path) is called, which works.

What's going on?

Thanks

Contact us