Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indexing a group of vectors

Status
Not open for further replies.

erpbell

Computer
Joined
Sep 15, 2005
Messages
1
Location
US
I would like to know how I can create a 1D array whose elements are vectors of various dimensions. For example for some array of vectors v(m), I would like to be able to call on a single vector (e.g. v(0) or v(3)) whose respective size would be 1:n-m, where m=0:n-1. Any suggestions?
 
Firstly, Matlab's indexes start (annoyingly) from 1, so your problem would need to be reformulated accordingly.

To answer your question, the only way to have differently sized rows in a 2D array is to make it a cell array:


v{1}=1:10;
v{2}=1:9;
v{3}=1:8;

% etc

You can access elements like this:

>> v{2}(3:5)

ans =

3 4 5


But... you can't do much with a cell array other than access its elements. Maybe you should be looking at the tril() and triu() functions instead?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top