Click here to Skip to main content
12,815,929 members (40,153 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 3 Apr 2003

An STL-Like Vector With Matlab Indexing Facilities

, 3 Apr 2003 GPL3
Rate this:
Please Sign up or sign in to vote.
An STL-Like Vector with Matlab indexing facilities.

Sample Image - mtVector.jpg


Vector is the basic data structure in MATLAB. It provides easy, fast, effective, and scalable data structures giving programming an algebraic view for data, even for complex data structures. Matlab allows you do develop fast technical solutions. However, MATLAB loops, and UIs are too slow :o. It is your responsibility to reformulate your code and data structures into matrices and vectors.

For example, to sum up a vector, you can write a simple counting loop. However, it is faster to use inner product with a vector of ones.

mtVector, mtRefVector

mtVector provides an STL-like vector. Actually, it wraps std::vector. Mathematical and indexing operators are added.

typedef mtVector<int> intVector;
 intVector iv1(15,   /* 15 elements */


 intVector iv2(15,   /* 15 elements */




iv1= < 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 >


print(iv1(4 to 12));

returns mtRefVector and prints:

iv1(4 to 12)= < 4 5 6 7 8 9 10 11 12 >


iv1(4 to 12)=iv2(4 to 12);

assigns values in iv2(4..12) to elements in iv1(4..12), and prints:

iv1= < 0 1 2 3 40 50 60 70 80 90 100 110 120 13 14 >

Moreover, it extends to select elements given a vector of their indices:

intVector iv3(15, 0,1,2,1,2,0,2,0,1,1,0,4,4,0,4);


returns mtRefVector and prints:

iv1(iv3.FindOnes())= < 9 18 27 360 540 720 810 990 1080 126 >

I guess mtVector and mtRefVector provide simple intuitive way to access and play with vectors. Simply, we can sort iv1, iv2 and iv3 given index vector of any other sorted vector.


gets indices that sorts iv5, and access iv1 in the same order.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

Generalhelp help help Pin
haider prolog1-Aug-06 4:33
memberhaider prolog1-Aug-06 4:33 
AnswerRe: help help help Pin
Mohammed Hossny1-Aug-06 16:07
memberMohammed Hossny1-Aug-06 16:07 
QuestionHow to convert from a STL-vector Pin
FinEngineer8-Dec-04 8:03
memberFinEngineer8-Dec-04 8:03 
AnswerRe: How to convert from a STL-vector Pin
Mohammed Hossny8-Dec-04 22:03
memberMohammed Hossny8-Dec-04 22:03 
QuestionHow using a vector index to select el. Pin
FinEngineer1-Dec-04 23:59
memberFinEngineer1-Dec-04 23:59 
AnswerRe: How using a vector index to select el. Pin
Mohammed Hossny2-Dec-04 14:58
memberMohammed Hossny2-Dec-04 14:58 
GeneralRe: How using a vector index to select el. Pin
FinEngineer2-Dec-04 23:40
memberFinEngineer2-Dec-04 23:40 
GeneralRe: How using a vector index to select el. Pin
Mohammed Hossny5-Dec-04 2:39
memberMohammed Hossny5-Dec-04 2:39 
Generalmatlab error Pin
yendluriusha16-Dec-03 19:41
memberyendluriusha16-Dec-03 19:41 
GeneralBoost multiarray library Pin
Jonathan de Halleux4-Apr-03 5:01
memberJonathan de Halleux4-Apr-03 5:01 
GeneralRe: Boost multiarray library Pin
Mohammed Hossny4-Apr-03 5:25
memberMohammed Hossny4-Apr-03 5:25 
GeneralRe: Boost multiarray library Pin
Jonathan de Halleux4-Apr-03 5:27
memberJonathan de Halleux4-Apr-03 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 4 Apr 2003
Article Copyright 2003 by cMoXIV
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid