Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
associative arrays, hash tables, indexing

Subject: associative arrays, hash tables, indexing

From: David Epstein

Date: 15 Aug, 2009 10:41:03

Message: 1 of 8

Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.

Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?

Thanks for any held

Subject: associative arrays, hash tables, indexing

From: Rune Allnor

Date: 15 Aug, 2009 10:46:11

Message: 2 of 8

On 15 Aug, 12:41, "David Epstein"
<David.Epstein.s...@remove.warwick.ac.uk> wrote:
> Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.
>
> Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?

Almost certainly not. There might be a hack somewhere
out there, but somebody who has the skills to come up
with one would not use matlab for any serious business.

Rune

Subject: associative arrays, hash tables, indexing

From: Bruno Luong

Date: 15 Aug, 2009 11:03:03

Message: 3 of 8

"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <h663bv$b6$1@fred.mathworks.com>...
> Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.
>
> Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?
>
> Thanks for any held

help containers.Map

I believe this class is provided on more recent Matlab.

Bruno

Subject: associative arrays, hash tables, indexing

From: David Epstein

Date: 15 Aug, 2009 11:06:03

Message: 4 of 8

"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <h663bv$b6$1@fred.mathworks.com>...
> Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.
>
> Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?
>
> Thanks for any help

Apologies about this email. I found an answer from Steven Lord, with subject "dict data type (Such as python)", suggesting the use of either containers or dynamic field names. I'll look into this, and I think I'll manage with this advice.

By the way, I did try quite hard to find relevant material in the news group before sending in my first query, but I seemed to have tried the wrong keywords.

Subject: associative arrays, hash tables, indexing

From: Bruno Luong

Date: 15 Aug, 2009 11:13:03

Message: 5 of 8

Rune Allnor <allnor@tele.ntnu.no> wrote in message <36209dc6-92a4-44ec-af33-fd43995fd700@z31g2000yqd.googlegroups.com>...
> On 15 Aug, 12:41, "David Epstein"
> <David.Epstein.s...@remove.warwick.ac.uk> wrote:
> > Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.
> >
> > Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?
>
> Almost certainly not. There might be a hack somewhere
> out there, but somebody who has the skills to come up
> with one would not use matlab for any serious business.

For older versions Matlab one can use java hash without having even a high skill. The proof is I have done it even I have zero Java knowledge.

Bruno

Subject: associative arrays, hash tables, indexing

From: Bruno Luong

Date: 15 Aug, 2009 11:22:01

Message: 6 of 8

"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <h664qr$ses$1@fred.mathworks.com>...
>
> Apologies about this email. I found an answer from Steven Lord, with subject "dict data type (Such as python)", suggesting the use of either containers or dynamic field names. I'll look into this, and I think I'll manage with this advice.

I don't believe structure (dynamic) fieldname access engine has any hashing in it. I could be wrong though.

Bruno

Subject: associative arrays, hash tables, indexing

From: Yair Altman

Date: 15 Aug, 2009 17:45:07

Message: 7 of 8

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h664l7$i0q$1@fred.mathworks.com>...
> "David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <h663bv$b6$1@fred.mathworks.com>...
> > Is there an easy method for making assocative arrays in Matlab, as in perl? More precisely, what I would like to do is to construct an array (presumably of cells) where one does not index into the array by using positive integers, but instead by using strings.
> >
> > Such structures are, I believe, implemented using hashtables. But I can't find any support for hashtables in Matlab. Is there any?
> >
> > Thanks for any held
>
> help containers.Map
>
> I believe this class is provided on more recent Matlab.
>
> Bruno


The new containers.Map class is available since Matlab 2008b (7.7). However, it is a scaled-down version of the java.util.Map interface on which it is based. Serious Matlab implementations which require key-value maps/dictionaries should still use the Java Map implementation classes to gain access to their larger functionality, if not performance. Matlab versions earlier than R2008b have no real alternative in any case and must use the Java classes.

The Java Collections include the following important interfaces and implementation classes:

1. Set: an interface which is implemented by classes characterized by their prevention of duplicate elements. Some notable implementation classes: EnumSet, HashSet, TreeSet, LinkedHashSet
2. List: an interface which is implemented by classes characterized by ordered elements (aka sequences), which may be duplicates of each other and accessed based on their exact List position. Specially optimized internal algorithms enable sorting, shuffling, reversing, rotating, and other modifications of the List. Some notable implementation classes: Vector, Stack, LinkedList.
3. Queue: an interface which is implemented by classes designed for holding elements prior to processing, in an ordered list typically accessible only at one (=head) or two (head & tail) positions. All classes include specialized insertion, extraction and inspection methods. Some notable implementation classes: ArrayDeque, LinkedList, PriorityQueue, java.util.concurrent.ArrayBlockingQueue, java.util.concurrent.SynchronousQueue, java.util.concurrent.DelayQueue
4. Map: an interface which is implemented by classes characterized by elements of unique keys paired with associated values. Maps contain specialized algorithms for fast retrieval based on a supplied key. Some notable implementation classes: EnumMap, HashMap, Hashtable, TreeMap, LinkedHashMap

See: http://java.sun.com/docs/books/tutorial/collections and: http://java.sun.com/javase/6/docs/technotes/guides/collections/

Yair Altman
http://UndocumentedMatlab.com
 

Subject: associative arrays, hash tables, indexing

From: Steven Lord

Date: 17 Aug, 2009 14:32:18

Message: 8 of 8


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
news:h665oo$pgl$1@fred.mathworks.com...
> "David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message
> <h664qr$ses$1@fred.mathworks.com>...
>>
>> Apologies about this email. I found an answer from Steven Lord, with
>> subject "dict data type (Such as python)", suggesting the use of either
>> containers or dynamic field names. I'll look into this, and I think I'll
>> manage with this advice.
>
> I don't believe structure (dynamic) fieldname access engine has any
> hashing in it. I could be wrong though.

It doesn't (unless the dynamic field names are longer than NAMELENGTHMAX, in
which case the hash value is the first NAMELENGTHMAX characters) but since
the OP asked for:

>>> More precisely, what I would like to do is to construct an array
>>> (presumably of cells) where one does not index into the array by using
>>> positive integers, but instead by using strings.

it seems like dynamic field names may satisfy his requirements.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us