File Exchange

image thumbnail

Multiple-Colon

version 1.6.0.0 (24.8 KB) by Bruno Luong
multiple colon-intervals

1 Download

Updated 03 Jan 2011

View Version History

View License

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

Cite As

Bruno Luong (2021). Multiple-Colon (https://www.mathworks.com/matlabcentral/fileexchange/29854-multiple-colon), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

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

Martin

Bruno Luong

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

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

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

Nate Jensen

Oh, ok. Thanks!

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

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?

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.

Oleg Komarov

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

The issue doesn't exist in the mex version.

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

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.

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.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

mcolonFolder/

mcolonFolder/overload/compatible/@char/

mcolonFolder/overload/compatible/@double/

mcolonFolder/overload/compatible/@int16/

mcolonFolder/overload/compatible/@int32/

mcolonFolder/overload/compatible/@int64/

mcolonFolder/overload/compatible/@int8/

mcolonFolder/overload/compatible/@logical/

mcolonFolder/overload/compatible/@single/

mcolonFolder/overload/compatible/@uint16/

mcolonFolder/overload/compatible/@uint32/

mcolonFolder/overload/compatible/@uint64/

mcolonFolder/overload/compatible/@uint8/

mcolonFolder/overload/fullmcolon/@char/

mcolonFolder/overload/fullmcolon/@double/

mcolonFolder/overload/fullmcolon/@int16/

mcolonFolder/overload/fullmcolon/@int32/

mcolonFolder/overload/fullmcolon/@int64/

mcolonFolder/overload/fullmcolon/@int8/

mcolonFolder/overload/fullmcolon/@logical/

mcolonFolder/overload/fullmcolon/@single/

mcolonFolder/overload/fullmcolon/@uint16/

mcolonFolder/overload/fullmcolon/@uint32/

mcolonFolder/overload/fullmcolon/@uint64/

mcolonFolder/overload/fullmcolon/@uint8/