Rank: 1566 based on 94 downloads (last 30 days) and 4 files submitted
photo

ben payne

E-mail

Personal Profile:
Professional Interests:
physics, linear algebra

 

Watch this Author's files

 

Files Posted by ben View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
13 Apr 2012 Screenshot Aperiodic array generation Functions to create aperiodic 1D, 2D arrays from Thue-Morse, Fibonacci, Rudin-Shapiro algorithms Author: ben payne aperiodic, thuemorse, thue, morse, rudinshapiro, rudin 18 0
05 May 2011 Screenshot structure factor Calculate structure factor based on positions of scatterers in real-space. Author: ben payne physics, scattering, structure, structure factor, plot 15 0
17 Mar 2010 Screenshot percolation 2D and 3D square matrices for counting straight-line percolation and collision count. Author: ben payne communications, demo, mathematics, statistics, physics 41 0
01 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne domino tiles random m..., domino, matrix, general, communications, simulation 20 10
  • 1.5
1.5 | 2 ratings
Comments and Ratings by ben View all
Updated File Comments Rating
01 Dec 2011 Feret diameter and oriented box Compute Feret diameters and oriented bounding box from label image Author: David Legland

Works as desired! Good documentation too.

23 Oct 2010 Sort Eigenvectors & Eigenvalues Sort a set of eigenvectors and corresponding eigenvalues Author: Calvin Price

Although this function may appear "trivial" to some, I found it very useful. Since I don't rely on the help text, I read the code to see what it does before using it. Thus, this script was useful and sufficiently commented. Thanks for writing it and saving me time.

17 Sep 2010 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne

more details at
http://mathworld.wolfram.com/Self-AvoidingWalk.html
http://en.wikipedia.org/wiki/Self-avoiding_walk

02 Nov 2008 Windows command line MATLAB process priority Set the priority of your MATLAB session in Windows. Author: Michael Kleder

Hello. I like starting processes from Start -> Run, so instead of using just
Start -> Run -> matlab
try
Start -> Run -> cmd /c start /belownormal matlab /nosplash

01 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne

I read about the difference between a script versus a function and this file is a proper script. It is not meant to be called by other actions. It is a stand-alone process.

Comments and Ratings on ben's Files View all
Updated File Comment by Comments Rating
17 Sep 2010 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne payne, ben

more details at
http://mathworld.wolfram.com/Self-AvoidingWalk.html
http://en.wikipedia.org/wiki/Self-avoiding_walk

05 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne D'Errico, John

Sigh. This is indeed a script file. But that does not mean that it should be so. Why do you submit a file to the FEX? Two main reasons I'll argue for. Marco is unexplainable. ;-)

1. Exposition. Teach someone how to use a certain method or technique. This should include a relatively massive amount of text, explaining why you have done something as you did. These submissions might often be as published m-files. Cell mode is also a handy tool here, allowing the user to change a parameter and see what happens to the result. Scripts are often used for this type of submission, and are entirely acceptable in my opinion. Well written, such an expository script will receive a top rating from me if it deserves that rating.

2. Use of the result in some further analysis. Most submissions on the FEX are of this type. As such, it only makes sense for the result to be returned by a function. The user has no wish to look deeply into your script to figure out, from the many variables that are generated, which are of even remote interest to the user. A function takes an input, returns an output. Some functions may arguably need no input. And some functions may produce no output variable, only a graphic, or a result written to a file. Even here, a script is a silly thing to use, trashing the workspace of the user just to generate a plot.

A script that generates its result as a fixed variable is kludgy, inelegant, and amateurish. Sorry, but it is. Suppose the user chooses to run your script a second time, but retaining the first result? Sorry, this script overwrites the first one. You cannot just direct the result into a different variable name.

You call this a "stand-alone" process. Sorry, but that concept is silly. Will any user ever run this code, look at the result, and then log out of matlab, happy with the result? At least, will they do this more than once? Why? What purpose does this tool serve? If it returns something of any value at all, then there must be another step after this that uses the result. If there is such another step, then you should have written it as a function.

Yes, I knew a lot of people from my past place of employment who wrote many script m-files. Those scripts were useful ONLY to themselves, but not to anyone else in the world. Not even useful to someone who sat in the next cubicle over from them. In that same environment, I wrote hundreds of functions that were used/shared by all of my co-workers. These functions formed the backbone of a thriving community of users. If you wish another example, look at the codes supplied with MATLAB itself. Do you see hardly any scripts (that are not demos?) Do you see thousands of functions?

The point is, if your code is to be useful to others in the world, a function is almost always the proper way to present it to that world. A WELL DOCUMENTED FUNCTION.

01 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne payne, ben

I read about the difference between a script versus a function and this file is a proper script. It is not meant to be called by other actions. It is a stand-alone process.

01 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne payne, ben

I uploaded a new version but it hasn't propagated yet.

I have an idea on implementing a function but it will probably have to wait until next semester.

I'm not sure why making the entire program a single function would help. The program is meant to stand on its own.

I'm not sure what "help styles" refers to.

I'm not sure why it seems "slow." What feature is slow?

The "waitbar" is interesting (I didn't know about it) but it does not apply to this program. A single realization is attempted, and when it fails the next realization is attempted. There are many failures for a "complete" realization (success) but a progress bar window is not applicable.

I'll try and keep updating until I earn "well done."

01 Nov 2008 domino tiles domino tiles random matrix, filling the matrix like in the game "snake" Author: ben payne D'Errico, John

Why not write it as a function? Return only the result that a user cares about. This is what functions are useful for. They are friendly to the user. A function, or any code for that matter, should have help. Even while you know how to use your own codes, other people who are strange to it will have no idea. So help them. Look at the help styles that you see in the tools the MathWorks already provides. Such help will greatly increase the usability of your code.

Preallocation is not always necessary. But this code seems slow, so there is something that is making it slow. Preallocation is a common cause. Use the profiler, find the bottlenecks in your code. If these arrays that are grown never get too large, then it may not be important. Find that out.

If you absolutely must grow an array without benefit of preallocation, then there are some tricks that can work. One of them is to create an array using zeros that is larger than it will ever need to be. Very often, even though you do not know the final size of an array, you may know a maximum that size will never exceed. Then just stuff your new points into that array using indexing. Keep track of the last element that you've inserted. At the end, chop off the extraneous elements.

Another trick that sometimes works is to use a cell array. Preallocate the cells to be empty, but have many such cells. Stuff your new elements into the cell array. Then at the end, you can concatenate all of the cells into one single flat array, using cell2mat. Remember a cell array is just a list of pointers, don't grow the number of cells if you can avoid it. There are a variety of these tricks one can use to avoid the problems of dynamic growth. One that I like is to use a few cells, each of which is preallocated to be fairly large. Then index into those cells, and when you run out of room in one cell, move onto the next.

Next, use tools like a waitbar to show the user what progress you are making. Surely there is some metric you can use to define the extent of progress. This gives them some comfort that your code is doing something, rather than just in an infinite loop. Or, perhaps MATLAB has crashed. A user will not know what has happened. So be friendly.

Good code is FRIENDLY.

My rating will continue to go up as I see improvements, and some authors may think me to be too hard on them. In the end, if you can tear a "well done" out of me, it is something to be proud of. You can then take the things you have learned to improve all of your future work.

Contact us