Code covered by the BSD License  

Highlights from
Multiple-Colon

5.0

5.0 | 4 ratings Rate this file 9 Downloads (last 30 days) File Size: 24.8 KB File ID: #29854

Multiple-Colon

by

 

30 Dec 2010 (Updated )

multiple colon-intervals

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| 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 file inspired Forecasting The Ftse 100 With High Frequency Data: A Comparison Of Realized Measures.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
25 Jul 2014 Jeffrey

The technical solution (1-4FLI96) linked in a previous comment is no longer available at that url. The solution was republished to MATLAB Central Answers here:

http://www.mathworks.com/matlabcentral/answers/143255-how-does-the-colon-operator-work

02 Apr 2013 Martin  
29 Dec 2011 Bruno Luong

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

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 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

25 Oct 2011 Nate Jensen

Oh, ok. Thanks!

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

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?

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.

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 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

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.

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.

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

Contact us