Editor's Note: This file was selected as MATLAB Central Pick of the Week
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
Bruno Luong (2021). Multiple-Colon (https://www.mathworks.com/matlabcentral/fileexchange/29854-multiple-colon), MATLAB Central File Exchange. Retrieved .
Inspired: Forecasting the FTSE 100 with high-frequency data: A comparison of realized measures
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
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
Andrea, go to the folder where all the files reside before invoking the installation command.
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
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
Oh, ok. Thanks!
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
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?
@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.
Sorry I didn't specify that I am using mcolon_MatlabBased.m.
The issue doesn't exist in the mex version.
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
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.
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.