Error message

  • Notice: Trying to get property of non-object in filter_default_format() (line 532 of /home/ntroutman/webapps/nt_drupal/modules/filter/filter.module).
  • Notice: Undefined variable: options in filter_process_format() (line 911 of /home/ntroutman/webapps/nt_drupal/modules/filter/filter.module).

Another Thing I Dislike About MatLab

Every so often I try to write some code in MatLab instead of my beloved Python, it generally turns into a marathon even of trying to get MatLab to do what I know how to make Python do in a couple of lines. One thing that I am missing right now is Python's sort and the ability to pass it in a key function that will be used in sorting an array. Now you might say, "Nathaniel, MatLab vectors are just numbers, why would you want to sort them in anything other than ascending or descening order?" And here is why, because the conceptially represent something other than a bunch of numbers! In my case I'm working with verticies, and just in 2-D mind you, and I would like to sort them.

First time I wanted to sort them by their distance from a target vertex. So if I have a matrix m such that m(1, :) is the first vertex, m(2,:) is the second vertex and so on I would like to sort them such that m(1,:) is now the closest of the vertices to a given vertex v. To me matlabs sortrow() function should take function handle that returns the value of a given row and use that value to sort the rows on. So you could do this

sortfunc = @(row) norm(row - v)
sorted = sortrows(vectors, 'KeyFunction', sortfunc)

And now sorted would have the vectors from vectors sorted by their distance from v. Makes sense huh?! But can you do this? No! Can you do something like that in Python? Yes! And there we go, yet another reason Python is better than MatLab, lol. Honestly, I really like somethings about MatLab, it has all sorts of things all ready coded for you. Like convhull for finding the convex hull of bunch of points! So, after spending hours searching google I finally found some code someone posted that does exactly what I wanted. You pass it in an array and a function handle and it spits out a list of indicies sorted by the function you gave it. I should right MatLab about this, maybe they'll see fit to add the capability later. It could be slower, thats fine, just let me do it with having to go use someone elses code! </rant>


its realy good thank you....evden eve nakliyat

Add new comment