Sunday, April 15, 2007

Matlab and hash tables

Unfortunately, Matlab does not have hash table functionality by itself. However, Matlab is based on Java, and provides programing interface to java classes. Consequently, it is possible to use Hash tables from Java!. It can be convenient and fast. You can store normal scalars, strings, matrices, etc in Java containers without much effort.
Below little example just to start with. It shows Hashtable, where we put few values, and afterwards we create iterator and iterate over Hashtable.

function testJavaHash
import java.util.*;
ja_h = Hashtable;

a='aaa';
b=12.23;
c=[1 2; 3 4];
s='marcin';

%add something to hash
ja_h.put(1,a);
ja_h.put(2,b);
ja_h.put(3,c);
ja_h.put(s,c);


%create iterator;
keys = ArrayList(ja_h.keySet( ));
iterator = keys.iterator();


%iterate over all keys
while iterator.hasNext()
key=iterator.next();
val=ja_h.get(key);
key
val
end

Unfortunately, it is not as nice as it looks like. For example it is not possible to use matrices as keys in hash tables. For instance:
ja_h.put([1 2],2);
ja_h.get([1 2])
ans =

[]
As it can be seen, ja_h.get returns nothing.
What I do do overcome this, I just convert matrix into string with num2str and back str2num. Not the best possible solution but it works for me in few limited situations:
ja_h.put(num2str([1 2]),2);
ja_h.get(num2str([1 2]))
ans =

2
However this solution does not work for e.g. 2x2 matrices ja_h.put(num2str([1 2; 3 4]),2);
ja_h.get(num2str([1 2; 3 4]))
ans =

[]
Similar problems are with mhashtable package available from Matlab Central File Exchange. I do not know why it is so difficult for Matlab engineers to create native Matlab support for Hash tables?

27 comments:

  1. Anonymous4:04 AM

    It is disappointments :(
    Probably nobody requested HashTable from Math works in official way.

    ReplyDelete
  2. Anonymous7:47 AM

    Thank you for your post.
    If you want to use an array as a key, a fast (not nice) way to do it is:

    The key for array w:

    w=[1 2;2 7];

    is

    >> num2str(w(w<=Inf)')

    ans =

    1 2 2 7

    ReplyDelete
  3. Anonymous8:05 AM

    I'm the say guay as before.
    You'd better use

    mat2str(w)

    instead of the above proposal.

    ReplyDelete
  4. Anonymous12:33 AM

    I'm one of those who will try every "easy" diet, but because of my lack of willpower, I either stay overweight or gain it all back after I lose it. Sie müssen auch sicher sein, dass Sie Ihre Einsätze auf der ganzen innerhalb der Roulette Tisch, bevor der Lieferant keine zusätzlichen Einsätze Signale sind. Nuvoryn is a dietary slimming supplement like no other as it not only helps a person lose weight, but it helps lose weight efficiently.

    My blog post; visit this weblink

    ReplyDelete
  5. Anonymous8:32 PM

    Wіth dozens of radio apps for i - Ρhone available
    іn i - Tunes, there is an app for every categοrу of music
    loνer to lovе. Another thing уou'll need is some strength to endure, because there's a gοod chance you'll be your own producer for the show or perhaps the best producer the show has. This not only allows listeners to listen to their favorite MP3 files along with their SIRIUS radio; it also lets them digitally record their favorite radio songs for instant playback.

    my webpage; wiki.internet-superstars.com

    ReplyDelete
  6. Anonymous12:01 AM

    Aw, this was an incredibly good post. Spending some time and actual effort
    to produce a very good article… but what can I say… I put things off
    a lot and never seem to get anything done.

    My web site :: gratis spiele spielen

    ReplyDelete
  7. Anonymous3:53 AM

    Mу partner аnd I stumbled over here fгom a different
    page anԁ thought I may as well check things out. ӏ
    likе what I seе so nоw i'm following you. Look forward to going over your web page again.

    Here is my web blog kostenlos spielen ohne anmeldung

    ReplyDelete
  8. Anonymous5:25 PM

    Right now it appears like Drupal is the top blogging platform out there right now.
    (from what I've read) Is that what you're using on your blog?


    Also visit my weblog :: similar web-site

    ReplyDelete
  9. Anonymous5:41 PM

    For moѕt rесent news you hаve to paу a quick visit the web and on ωorlԁ-wide-web I fοund thiѕ sіte as a finest ѕitе fοr most recent updates.



    Feel frеe to visit my web sіtе Speedy Methods Of internet - Some Thoughts

    ReplyDelete
  10. Anonymous6:14 AM

    What I didn't know was how I would get all of what I wanted in just six hours. Many people will be happy with replaceable batteries for home use and occasional outings. It is a more reliable choice when compared to traditional concrete or wooden barriers for several reasons.

    Here is my webpage; Choosing Products For radio
    My web page :: gratis spiele

    ReplyDelete
  11. Anonymous10:06 PM

    Ηi to all, as I am actuаlly keen of
    readіng thіs ωeblοg's post to be updated regularly. It contains pleasant stuff.

    Here is my web-site: spiele spielen kostenlos

    ReplyDelete
  12. Anonymous4:44 PM

    Unquestionаbly believe that which yоu
    stated. Your faνοrite reаsοn аρρeaгeԁ
    tο be on the net the easiеѕt thіng to
    be aware οf. I saу to you, ӏ сeгtainlу gеt
    irkеd while people think about worrіes that they plainly dоn't know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks

    Have a look at my page: spiele spielen kostenlos

    ReplyDelete
  13. Anonymous3:37 PM

    There are many different kinds of tools and techniques required
    to deliver an exceptional SEO India results. B) SEO basics - Image
    2: Select-'English' and 'All Countries and Territories'. It's a competitive world out there on the world-wide web, but SEO consulting can help you dramatically improve your odds of being found in the din and getting your message across. This can be a great tool when selling products online, as a website can be designed to offer either luxury or bargain-oriented goods, based on traffic analysis. SEO must be implemented by following a step by step process. It would cut the marketing project to fit it into your budget. They make their strategy according to the audience their client is targeting. When SEO services are working for you, you should always be ready to capitalise on innovations and fresh marketing opportunities. Its professionals would do hard work to achieve the high traffic objective and they might taste success in their attempt but they would desist from boasting anything about their success. Most of the XML sitemap generators online are simple enough for anyone to use. organic search, frequency of blog posts, frequency of on-page optimization, the relative importance of links, the use of social media, the best way to measure results, etc. The concepts make use of the current social networking sites, which are very popular among the online audience. ' Every page should be optimized with additional keywords.
    Here you will need an SEO agency such as Webfirm to try and
    run damage limitation. These professionals follow ethical SEO strategy and effectively implement it that finally increases your website visibility.
    As of now, Thomas Lenarz has helped many people
    get the information on reputed SEO companies. Today, it is necessary that you scout the market for the
    best SEO Host that can help you achieve this. A person can find all sorts
    of products available at various prices on the internet.
    First of all a market survey is done by them as to know the competitors analysis.
    Never post a half edited article, and never settle for less than your best.


    my web page ... fmf.bigpi.biysk.ru
    my website - www.blogphotovideo.com

    ReplyDelete
  14. Anonymous1:07 PM

    If you are going for finest contents like I do, just pay a quick visit this
    web page all the time since it gives quality contents, thanks

    Here is my web blog ... http://pvypovaskiy.blog.com/2013/01/05/they-usually-dote-on-the-oldest-child-until-heshe-is-old-enough-not-to-need-so-much-parental-supervisor/
    my website :: omerta city of gangsters

    ReplyDelete
  15. Anonymous8:00 AM

    I knοw this if off topic but Ι'm looking into starting my own weblog and was wondering what all is needed to get setup? I'm assumіng having
    a blog like yοurs wοulԁ
    cоst a prettу penny? I'm not very internet savvy so I'm
    not 100% certain. Any suggestions or advice would be greatly appreciated. Kudos

    My blog post :: youtube converter

    ReplyDelete
  16. Anonymous4:22 PM

    When you quit, you can immediately feel its decision within 24 hours, health benefits, which can cause you to not smoke forever.
    If you don't want to use Safari to navigate to pages, zoom in, and read articles, Byline may be just the app for you. Rechargeable batteries last longer than single use batteries before disposal and reduce the number of batteries you buy.

    Look at my page :: youtube videos downloaden - bildungsstreik.net

    ReplyDelete
  17. Anonymous10:55 AM

    There are many different kinds of tools and
    techniques required to deliver an exceptional SEO India results.
    The objective is to arrange your passions as carefully as
    possible with your online promotion company. It's a competitive world out there on the world-wide web, but SEO consulting can help you dramatically improve your odds of being found in the din and getting your message across. The only thing that cannot be "fixed" later is your blog and post titles. NOW, I don't mean you should
    just put keyword spam in your footer. Meta Name and Meta Description Tags are two
    of the important ones. Domain Authority is influenced by:.

    There are many tools online to help you research relevant keywords, such as the Google Adwords Keyword Tool.
    Online research is required to determine the packages and SEO
    Company. Over the years, web promotion has made a mark in the industry and has helped numerous entrepreneurs to build large business return through web.
    They want to know things about how to create effective copy, general marketing tips and
    maybe even stuff about social media. Don't Forget to Replace the Default Favicon with Your Logo. Their success is based on how many sales and customers you bring. Such services also include some research that will need to be done so they can apply this research on major keyword. These professionals follow ethical SEO strategy and effectively implement it that finally increases your website visibility. The sooner a site is presented in the search result, or the higher it “ranks”, the more searchers will visit the site. With most visitors noting the first 3-5 web links of the first page, further sustained SEO efforts bring the company web link to that web positioning high up as much as possible. A person can find all sorts of products available at various prices on the internet. The internet has become an integral part of our lives that according to the latest statistics, almost 1 billion Americans access the internet. Image Optimization is also a part of SEO services in Pune.

    Here is my web blog: backlinkbasis.com/linkpy..

    ReplyDelete
  18. Anonymous2:30 PM

    These five free basketball game apps for the i - Phone will surely help you get your
    game on. Each program will have a box with a checkmark, find the programs you'd like to uninstall and uncheck that box. Even when things seem hopeless, Kiko's narration provides some great comedy relief.


    Feel free to surf to my blog post; www.ruderwiki.de

    ReplyDelete
  19. Anonymous2:49 PM

    What I dіdn't know was how I would get all of what I wanted in just six hours. Another thing you'll neeԁ is sοme
    strength to endurе, because there's a good chance you'll be youг own ρroducer foг the show or perhaρs
    the best рroduceг the shoω has. Α ΜОBΙLЕ APP GIVES THE STAТION A DІREϹT MARKETING CHANΝEL
    TO CОMMUΝΙCATE WITH THEIR LIЅTΕNERS.


    Vіsit my web page; http://test.party-mix-radio.com/

    ReplyDelete
  20. Anonymous2:36 AM

    Please supplement charge before use when the battery has been kept for a
    long time. As you lift out the screen you'll see it is still attached via a ribbon cable. While the older 17 inch Mac - Book Pros lack the benefits of the unibody design, they do have the added feature of user-replaceable batteries.

    Here is my web-site: youtube videos downloaden

    ReplyDelete
  21. Anonymous3:26 PM

    When you quit, you can immediately feel its decision within 24 hours, health benefits, which can
    cause you to not smoke forever. So, follow the battery power
    saving tips above to get the most bang for your buck. Both
    Intel and AMD contain information built in the processor to allow the processor to be used efficiently
    with mobile computing saving on battery life while giving the best performance.


    my website - spiele spielen kostenlos - www.hillclimbfans.com

    ReplyDelete
  22. Anonymous1:25 AM

    You could experience natural disasters like cyclone, tornadoes,
    earthquakes, and fire. Your best bet is to choose a video card that
    is just one or two steps down from the number one card
    now. So all you gaming maniacs, log on to your internet connected by
    service provider like Verizon Fi - OS Internet and have a blast of a time.



    Review my page: http://pyconuk.net/

    ReplyDelete
  23. Anonymous8:59 PM

    The application also offers some freebies like ID3 tagger and audio trimmer.
    You will get an account and once you get yourself registered with Odyssey Streaming.
    The key is to have a clear understanding of the market so the money
    spent on broadcast advertising isn't wasted.

    Feel free to visit my web site internet radio sender

    ReplyDelete
  24. Anonymous8:23 AM

    Over time, many of these radio personnel will be readily agreeable to
    featuring the entrepreneur whenever they release new products or services.
    In addition to music, there is a wealth of other audio and informational materials out there to investigate.

    The viewing angle is extra wide, making it easier for you
    to read or even allow others to read with you.


    Also visit my web page http://www.online-radioportal.de

    ReplyDelete
  25. Anonymous10:57 PM

    However, there are other items that must be taken into consideration when selling a home.
    Savings bonds can be purchased in electronic form, but the most familiar are the paper Series EE bonds purchased for one-half the denomination of
    the bond. You may also try to sell old i - Pad and its parts
    to a person who needs them as spares and will
    make a good use of your broken electronic device.


    Feel free to visit my web site ... science fair projects

    ReplyDelete
  26. Anonymous5:16 PM

    You can also utilise wealth travel from $100 to $1500.
    payday loansThis is why you should also substantiate that the online investor you are take
    out instantaneous cash help at the time of
    temporary state. Such a loan sum can be paid back easy on next day
    as to toast but in this case you are unsusceptible.
    Just in case receivingquick loans no approval checkplan,
    it's in reality may be caught off guard, will be paid no present dollars on designated topics.

    ReplyDelete
  27. Anonymous10:02 AM

    It is needful to carry through have to state any of your written document relating to
    your ad hominem realness. You have to return the magnitude oversimplified online request with just a few individual detail.
    payday loans ukBecause of the littler paycheque, the high curiosity rate fast loans can be availed
    with the aid of flying loans. Even if you are keeping any approval ratings such as CCJs, IVA, defaults or else financial debt, you can
    admittance which will take plus fast loans no approval bill of
    exchange without any fuss. When you drag a security interest account,
    you may authentic subject of US.

    ReplyDelete