Code covered by the BSD License  

Highlights from
Multiple-Colon

5.0

5.0 | 3 ratings Rate this file 1 Download (last 30 days) File Size: 24.84 KB File ID: #29854

Multiple-Colon

by Bruno Luong

 

30 Dec 2010 (Updated 03 Jan 2011)

multiple colon-intervals

| Watch this File

File Information
Description

Return a concatenation of multiple colon-intervals.

User provides left, step, and right bound.

>> mcolon([0 10],[1 2],[2 14])

ans = 0 1 2 10 12 14

Acknowledgements
This submission has inspired the following:
Forecasting the FTSE 100 with high-frequency data: A comparison of realized measures
MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
30 Dec 2010 Oleg Komarov

Two small remarks:
- H1 line missing
- You set the tolerance to 1e-12 when in the help you say it's set to 1e-10.

Great function.

01 Jan 2011 Diederick

Nice function, good idea.
You might to have a look at http://www.mathworks.com/support/solutions/en/data/1-4FLI96/index.html?solution=1-4FLI96, especially the reference implementation attached to it.

05 Sep 2011 Oleg Komarov

Issue or expected behaviour?

% dates contains MATLAB serial dates
% column 1 --> i1
% column 2 --> i2

dates = [731583.333361354, 731583.687342535
         731584.333522199, 731584.687342755
         731587.333360232, 731587.687342465
         731588.333364942, 731588.687341123
         731589.333520081, 731589.687344711
         731590.333361007, 731590.687345613
         731591.333359861, 731591.687343831
         731594.333363900, 731594.687342072];

% d is 1 second step (60s*60m*24h = 86400s)
d = 1/86400;

% 'tol' is slightly less than a millisecond
tol = 1/(86400*1000)-eps;

% Consider one period
n = 1;
issorted(mcolon(dates(n,1), d, dates(n,2),'tol',tol)) % 1

% Consider 8 periods
n = 1:8;
issorted(mcolon(dates(n,1), d, dates(n,2),'tol',tol)) % 0

05 Sep 2011 Oleg Komarov

Sorry I didn't specify that I am using mcolon_MatlabBased.m.

The issue doesn't exist in the mex version.

05 Sep 2011 Bruno Luong

@Oleg, there is an indeed an issue with Matlab engine due to finite precision of floating point, and because the interval concatenation fails due around the CUMSUM statement used somewhere in the code.

I recommend using the Mex engine (faster and more reliable), where no cumulative sum is employed. The Matlab engine is simply a poor-guy replacement and somewhat educational valuable.

24 Oct 2011 Nate Jensen

Bruno, great function, I really appreciate it, and it works well on my 64 bit pc. I haven't been able to install the mex function on my 32 bit though. These are the errors that I keep getting:

lcc preprocessor warning: mcolonmex.c:137 No newline at end of file
Warning mcolonmex.c: 78 local `pointer to double PrS' is not referenced
Warning mcolonmex.c: 78 local `pointer to double PrA' is not referenced
Error mcolonmex.c: 114 compiler error in _kids--Bad rule number 0

The preprocessor warning was easy enough to fix, and the other warnings shouldn't matter, but I haven't been able to figure out how to get rid of the compiler error on line 114. Any suggestions?

25 Oct 2011 Bruno Luong

Nate: the problem is caused by a well-known bug of LCC

http://www.mathworks.de/matlabcentral/newsreader/view_thread/158562

The only workaround is to remove line 113-115 of the file mcolonmex.c if you don't need to work with uint64 data type.

Hope it helps

25 Oct 2011 Nate Jensen

Oh, ok. Thanks!

29 Dec 2011 Andrea

Sorry, the full message is:

C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: 'mcolonmex.c' not found.
 
??? Error using ==> mex at 206
Unable to complete successfully.

Error in ==> mcolon_install at 32
    mex -v -O mcolonmex.c

29 Dec 2011 Andrea

Hi Nate, when I run mcolon_install I get this error:

C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: 'mcolonmex.c' not found.
 
??? Error using ==> mex at 206
Unable to complete successfully.

Error in ==> mcolon_install at 32
    mex -v -O mcolonmex.c

29 Dec 2011 Bruno Luong

Andrea, go to the folder where all the files reside before invoking the installation command.

Please login to add a comment or rating.
Updates
30 Dec 2010

Add optional MEX engine

30 Dec 2010

Minor correction from Oleg's comments

31 Dec 2010

Fix an overflow bug for colon with integer types

31 Dec 2010

Various improved performance
User can set tolerance once

03 Jan 2011

Fix installation bugs

Tag Activity for this File
Tag Applied By Date/Time
colon Bruno Luong 30 Dec 2010 08:55:45

Contact us at files@mathworks.com