tag:www.mathworks.com,2005:/matlabcentral/fileexchange/feedMATLAB Central File Exchangeicon.pnglogo.pngMATLAB Central - File Exchange - type:Example category:"Mathematics"User-contributed code library2015-03-29T07:43:04-04:001191100tag:www.mathworks.com,2005:FileInfo/496922015-02-12T18:47:15Z2015-03-29T05:05:01ZgptoolboxUseful functions for geometry processing, constrainted optimization and image processing.<p><a href="https://github.com/alecjacobson/gptoolbox/">https://github.com/alecjacobson/gptoolbox/</a>
<br />This is a toolbox of useful matlab functions for geometry processing. There are also tools related to constrainted optimization and image processing. Typically these are utility functions that are not stand alone applications.
<br />Here's an incomplete list of cool features this matlab toolbox contains:</p>
<p> - wrappers for TetGen, Triangle, QSlim, meshfix
<br /> - mesh smoothing
<br /> - mesh clean up (remove duplicates, remove unreferenced)
<br /> - geodesic distances on triangle and tetrahedral meshes
<br /> - mesh quantities and queries (normals, discrete gaussian curvature, list boundary edges, topology, angles, dihedral angles etc.)
<br /> - mesh deformation (as-rigid-as-possible (ARAP), moving least-squares, etc.)
<br /> - mesh parameterization (harmonic, least squares conformal, ARAP, etc.)
<br /> - automatic skinning weight computation (bounded biharmonic weights, bone heat)
<br /> - 2D triangle mesh from binary image
<br /> - Input/Output for many mesh formats (.obj,.off,.stl,.wrl,.ply,.mesh,.node,.ele,.poly,.smf,.bdl,.face)
<br /> - discrete differential geometry operators for triangle and tetrahedral meshes (cotangent Laplacian, gradient, divergence)
<br /> - quadratic programming, active set solver
<br /> - scribble-based image colorization, diffusion curves
<br /> - exact (un)signed distance field computation for meshes
<br /> - constructive solid geometry operations on meshes, booleans
<br /> - accelerated point location in triangle and tetrahedral meshes
<br /> - image dithering
<br /> - deep matlab function dependency</p>Alechttp://www.mathworks.com/matlabcentral/profile/authors/5297920-alecMATLAB 8.4 (R2014b)Aerospace ToolboxImage Processing ToolboxMost of gptoolbox is pure matlab. There are a few functions that expect the image processing toolbox or aerospace toolbox to be installed. There are also a few mex functions which have other dependencies: stl, eigen, libigl, boost, cgal, cork.5355falsetag:www.mathworks.com,2005:FileInfo/478372014-09-13T11:18:56Z2015-03-18T05:06:11ZEllipsoid MethodThe ellipsoid method with visualization features.<p>The Ellipsoid Method implemented in MATLAB. It finds a feasible solution to a set of inequalities (point within a polytope). It can use a central, shallow or deep cut. An almost optimal solution can be obtained by sliding objective method. It supports to plot the ellipses, the separating hyperplane and other insights for simple 2-dimensional problems.
<br />It was written as part of my master's thesis at Technische Universität München in 2014.</p>Florianhttp://www.mathworks.com/matlabcentral/profile/authors/3457126-florianMATLAB 8.3 (R2014a)MATLABFor plotting, Ellipse_plot and con2vert from Fileexchange are required.789413844falsetag:www.mathworks.com,2005:FileInfo/200582008-05-26T09:03:49Z2015-03-13T21:53:38ZAdaptive numerical limit (and residue) estimationNumerical extrapolation of a limit (with an error estimate) from only function values<p>LIMEST will find the limit of a general function (specified only for evaluation) at a given point. You might think of limest like quad, but for limits.
<br />While to me this seems to appear more often as a homework exercise than anything else, it was an interesting problem to solve as robustly as possible for a general case.</p>
<p>As an example, I'll use a moderately difficult one that is simple to analyze, but more difficult to deal with numerically.</p>
<p>fun = @(x) (exp(x)-1-x)./x.^2;</p>
<p>This function cannot be evaluated in MATLAB at x = 0, returning a NaN. While a Taylor series expansion shows the limit to be 1/2, the brute force evaluation of fun anywhere near zero results in numerical trash because of the two orders of cancellation.</p>
<p>fun(0)
<br />ans =
<br /> NaN</p>
<p>fun(1e-15)
<br />ans =
<br /> 110223024625156</p>
<p>fun(1e-10)
<br />ans =
<br /> 827.403709626582</p>
<p>fun(1e-5)
<br />ans =
<br /> 0.500000696482408</p>
<p>fun(1e-2)
<br />ans =
<br /> 0.501670841679489</p>
<p>Limest computes the limit, also returning an approximate error estimate.</p>
<p>[lim,err] = limest(fun,0)
<br />lim =
<br /> 0.499999999681485
<br />err =
<br /> 2.20308196660258e-09</p>
<p>I've now added the residueEst tool, for computation of the residue of a function at a known pole. For example, here is a function with a first order pole at z = 0
<br />
<br />[r,e]=residueEst(@(z) 1./(1-exp(2*z)),0)
<br />r =
<br /> -0.5
<br />e =
<br /> 4.5382e-12</p>
<p>Again, both an estimate of the residue, as well as an uncertainty around that estimate are provided. Next, consider a function with a second order pole around z = pi.
<br />
<br />[r,e]=residueEst(@(z) 1./(sin(z).^2),pi,'poleorder',2)
<br />
<br />r =
<br /> 1
<br />e =
<br /> 2.6336e-11</p>
<p>See the included demos for many other examples of use.</p>John D'Erricohttp://www.mathworks.com/matlabcentral/profile/authors/869215-john-d-erricoMATLAB 7.4 (R2007a)Moderately older versions of Matlab should be able to use this utility with an inline function.13490falsetag:www.mathworks.com,2005:FileInfo/482082014-10-21T09:35:41Z2015-03-13T05:18:05ZGIBBON: The Geometry and Image-Based Bioengineering add-On for MATLABGIBBON: The Geometry and Image-Based Bioengineering add-On for MATLAB<p>The Geometry and Image-Based Bioengineering add-On for MATLAB
<br />GIBBON is an open-source MATLAB toolbox by Kevin M. Moerman and includes an array of image and geometry visualization and processing tools and is interfaced with free open source software such as TetGen, for robust tetrahedral meshing, and FEBio for finite element analysis. The combination provides a highly flexible image-based modelling environment and enables advanced inverse finite element analysis.
<br />This can be considered a beta version. Documentation is still a work in progress. For installation instruction see <a href="http://www.gibboncode.org/installation/">http://www.gibboncode.org/installation/</a>
<br />Tested on Windows 7 64-bit and UBUNTU 14.04 64-bit with MATLAB R2014b. </p>
<p><a href="http://www.gibboncode.org">www.gibboncode.org</a></p>
<p>DOI: 10.5281/zenodo.12214
<br /><a href="https://zenodo.org/record/12214">https://zenodo.org/record/12214</a></p>
<p>A conference paper on the toolbox:</p>
<p>Moerman, K.M., A.J. Nederveen, and C.K. Simms, "Image Based Model Construction, Boundary Condition Specification and Inverse FEA Control: A Basic MATLAB Toolkit For FEBio", in Proceedings of the 11th International Symposium, Computer Methods in Biomechanics and Biomedical Engineering. 2013: Salt Lake City, Utah, USA.</p>Kevin Moermanhttp://www.mathworks.com/matlabcentral/profile/authors/975857-kevin-moermanMATLAB 8.4 (R2014b)Image Processing ToolboxOptimization ToolboxStatistics ToolboxMATLABFEBio (www.febio.org)
TetGen (included)falsetag:www.mathworks.com,2005:FileInfo/497482015-03-11T21:59:56Z2015-03-11T21:59:56Z"Introduction to MATLAB" demo filesDemo files from the "Introduction to MATLAB" webinar<p>Demo files from the "Introduction to MATLAB" webinar. Files include images and video used in webinar.</p>Andy Théhttp://www.mathworks.com/matlabcentral/profile/authors/4310429-andy-theMATLAB 8.4 (R2014b)Image Acquisition ToolboxImage Processing ToolboxMATLABfalsetag:www.mathworks.com,2005:FileInfo/499502015-03-08T21:21:39Z2015-03-08T21:21:39ZBatched partitioned nonlinear least squaresSpeed up when you have a very large number of nonlinear least squares problems, but with one model<p>Occasionally I see requests to solve very many nonlinear least squares problems, all of which have the same model, but different sets of data. The simple answer is a loop, or you might use a parallel computing solution. However, you can also use a capability that is built into the optimization toolbox solvers - to allow you to solve many small problems in parallel with a block diagonal Jacobian matrix.
<br />For example, suppose you are asked to estimate the coefficients for the model</p>
<p> y = a1 + a2*exp(a3*x)</p>
<p>This is a simple problem to solve using any nonlinear regression tool. (I recommend my own fminspleas, also on the File Exchange.) But suppose you have 10000 sets of data, so you need to solve for 10000 sets of parameters? You could just use a loop, but loops are not always the most efficient way to solve a problem.</p>
<p>batchpleas is the tool for this problem. It will typically allow for an order of magnitude enhancement in throughput, without the need for any parallel processing toolbox. For example the example I provide in the included demo showed a 10-1 speedup when fitting a set of 10000 curves to data, each with 3 parameters to estimate.</p>John D'Erricohttp://www.mathworks.com/matlabcentral/profile/authors/869215-john-d-erricoMATLAB 8.4 (R2014b)Optimization Toolboxfalsetag:www.mathworks.com,2005:FileInfo/351042012-02-16T07:20:31Z2015-02-23T17:38:18ZLBFGSB (L-BFGS-B) mex wrapperMex wrapper for lbfgsb v3.0 fortan library. L-bfgs-b solves box-constrained
optimization.<p>----------------------- UPDATE Feb 2015 ----------------------------------------
<br />Due to the difficulty of compiling Fortran for most people (including myself), I have converted the v3.0 L-BFGS-B Fortran code into C (using f2c and some hand-coded changes). I have a new wrapper for it as well; both the C code and the mex wrapper are available at: <a href="https://github.com/stephenbeckr/L-BFGS-B-C">https://github.com/stephenbeckr/L-BFGS-B-C</a>
<br />You are still welcome to try this code, and if you get it to compile, there will be no major difference in speed or performance. Feel free to leave comments/feedback below. However, I will no longer support this version of the code.
<br />----------------------- END UPDATE ----------------------------------------------</p>
<p>Description: L-BFGS-B is a variant of the well-known "BFGS" quasi-Newton method. This variant uses limited-memory (like L-BFGS), and also handles simple constraints (to be specific, bound constraints, so this includes x >=0 constraints).
<br />The authors of LBFGSB have had fortran implementations available since 1996, but in 2011 they released a major update (v3.0) which has an improved algorithm (you should use this version!). There are existing mex file wrappers for earlier versions, but none worked with v3.0, so I created this file.</p>
<p>This submission tries to make the mex wrapper simple, and then includes a nice .m file solver that requires very few parameters, yet is customizable for advanced users. Run the compile_mex.m file to compile the files. compile_mex.m also includes two quick sanity checks (the file driver1.m is a helper file for one of these checks)</p>
<p>I also have an example of using L-BFGS-B to solve the non-negative least-squares
<br />(NNLS) problem, and comparing it to other existing solvers. To put it simply,
<br />L-BFGS-B is a fantastic NNLS solver, and much better than Matlab's lsqnonneg.</p>
<p>Links:</p>
<p>The fortran lbfgsb is at <a href="http://users.eecs.northwestern.edu/~nocedal/lbfgsb.html">http://users.eecs.northwestern.edu/~nocedal/lbfgsb.html</a>,</p>
<p> There are also versions 2.1 and 2.4 of the library.</p>
<p>For v 2.1, Peter Carbonetto's mex interface works; see <a href="http://www.mathworks.com/matlabcentral/fileexchange/15061-matlab-interface-for-l-bfgs-b">http://www.mathworks.com/matlabcentral/fileexchange/15061-matlab-interface-for-l-bfgs-b</a> and also <a href="http://www.cs.ubc.ca/~pcarbo/lbfgsb-for-matlab.html">http://www.cs.ubc.ca/~pcarbo/lbfgsb-for-matlab.html</a></p>
<p> For v 2.4 (I don't know where you can find this version though), use the mex files from here: <a href="http://www.cs.toronto.edu/~liam/software.shtml">http://www.cs.toronto.edu/~liam/software.shtml</a></p>
<p>The wikipedia page (this was mainly edited by one of the authors of the L-BFGS-B algorithm): <a href="http://en.wikipedia.org/wiki/L-BFGS-B:_Optimization_subject_to_simple_bounds">http://en.wikipedia.org/wiki/L-BFGS-B:_Optimization_subject_to_simple_bounds</a></p>
<p>For installing on 64-bit Windows, if you need a compiler, see <a href="http://www.mathworks.com/support/compilers/R2011b/win64.html">http://www.mathworks.com/support/compilers/R2011b/win64.html</a></p>
<p>=== Update, Jan 2015 ===
<br />I am not able to completely support installation/compiling of this toolbox. If you have issues, please mention in the comments below (there are also some solutions from other users in the comments below). Newer versions of Matlab keep changing how files compile (e.g., recent versions do not allow fortran and C to be compiled together), and I am not able to keep up.</p>
<p>If you are using mac or linux, there is a good chance that we can get it to compile. If you are using 64-bit Windows, there is a slim chance you can get it to compile. So please take this as a warning! If anyone is good at software installation and wants to take over the installation script, please do so. The actual wrapper script is quite simple.</p>Stephen Beckerhttp://www.mathworks.com/matlabcentral/profile/authors/747762-stephen-beckerMATLAB 7.10 (R2010a)MATLABCompile the mex file with compile_mex.m. Needs a C and fortran compiler. See user comments for issues with recent versions of Matlab and with Windows 64-bit.33888157109081484815061falsetag:www.mathworks.com,2005:FileInfo/494342015-02-11T20:13:13Z2015-02-11T20:13:13ZRubik's Cube® Solver using an Arduino and MATLABSolve Rubik’s Cube® using image processing and Arduino-controlled servo motors<p>In this entry, we build a robot that solves a Rubik’s Cube® using MATLAB, a SparkFun RedBoard (Arduino Uno clone), two servo motors, and a webcam. The submission contains all of the code used to control the robot, a detailed article describing how the robot was built and programmed, and several videos of the final result. Download this submission if you’re interested in learning about our project. Or use it as a starting point for building and controlling your own Rubik’s Cube solving robot.
<br />In addition to hardware components, this project requires MATLAB and Image Processing Toolbox. It also uses MATLAB Support Package for Arduino® Hardware, which can be downloaded for free here: <a href="http://www.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-arduino%C2%AE-hardware">http://www.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-arduino%C2%AE-hardware</a>
<br />The initial setup of the project involved building the robot from readily available materials. In addition to the Arduino device, webcam, and servos, we used LEGO bricks, an acrylic sheet, and hard polystyrene foam. The robot was designed with two main parts. A holder holds the cube from below in an open-topped box and can rotate the cube in the horizontal plane. A gripper arm can be lowered over the cube from above to hold two layers still while the holder rotates one face from below. The gripper arm can also be pushed forward to flip the cube to a different side.
<br />With the entire robot assembled and calibrated, solving the cube involves two steps:</p>
<p>1. Read the initial state of the scrambled cube.</p>
<p>MATLAB functions were written to control the servo motors on the Arduino so they could rotate the entire cube in the holder and flip it to a different side. These functions are used to rotate the cube so each of the 6 faces are facing up and capture an image of the face with a webcam. Using Image Processing Toolbox, the color of each facelet is determined. A custom MATLAB UI is used to validate the results and correct any errors.</p>
<p>2. Solve the cube.</p>
<p>The algorithm used for solving the cube is the Thistlethwaite 45 (T45) algorithm. It was used because a MATLAB implementation of the algorithm was already available on the MATLAB Central File Exchange as part of the submission here: <a href="http://www.mathworks.com/matlabcentral/fileexchange/31672-rubik-s-cube-simulator-and-solver">http://www.mathworks.com/matlabcentral/fileexchange/31672-rubik-s-cube-simulator-and-solver</a></p>
<p>The output of the T45 algorithm determines which faces should be turned. This is then converted to a sequence of moves on the robot that could rotate the cube, flip it to a different side, and turn a single face. Once all the steps are complete, the cube is solved.</p>MathWorks MATLAB Hardware Teamhttp://www.mathworks.com/matlabcentral/profile/authors/4922363-mathworks-matlab-hardware-teamMATLAB 8.3 (R2014a)Image Processing ToolboxMATLABMATLAB Support Package for Arduino Hardwarefalsetag:www.mathworks.com,2005:FileInfo/450842014-01-17T17:04:47Z2015-02-04T05:13:02ZSaivDr PackageSystem object definitions for sparsity-aware image and volume data restoration<p>This package provides System object definitions for sparsity-aware image and volume data restoration with non-separable oversampled lapped transforms (NSOLTs). This package is developed in order for making
<br />* Experiments,
<br />* Development and
<br />* Implementation
<br />of sparsity-aware image and volume data restoration algorithms simple.</p>Shogo Muramatsuhttp://www.mathworks.com/matlabcentral/profile/authors/68415-shogo-muramatsuMATLAB 8.3 (R2014a)Image Processing ToolboxOptimization ToolboxSignal Processing ToolboxMATLABfalsetag:www.mathworks.com,2005:FileInfo/365342012-05-04T10:03:48Z2015-01-27T04:21:47ZHPF - a big decimal classHigh precision floating point arithmetic, a new class written in MATLAB<p>Very often I see people asking for a tool that offers more than 16 digits or so of accuracy. MATLAB itself only allows you to use doubles or singles in standard arithmetic, so that is the normal limit. The fact is, most of the time, if you can't do it with a double, you are doing something wrong. Good practices of numerical analysis are worth far more than any high precision tool. Even so, there are times when you will have a use for a bit of extra precision. And some of you will just want to play in the huge number sandbox. While some of you may use tools like that written by Ben Barrowes, HPF is written purely in MATLAB, so no compiles are needed. For all of you, whatever your reasons, I offer HPF, a High Precision Floating point tool.
<br />In fact, the reason I wrote HPF was for my own purposes. I wanted to learn to use the classdef tools in MATLAB that were released a few years ago. As well, I wanted to try building such a tool as a natural extension of the VPI tools I wrote some time ago. And I wanted to learn some techniques for working in a high number of digits. The result is HPF.
<br />There are a few ideas I've introduced for how HPF interacts with the user. For example, HPF can work in any number of decimal digits, as chosen by the user. You can set the number of digits as a default. Thus, if you want to always work in 30 decimal digits, with 2 guard digits on all computations, then type this at the command prompt:
<br />DefaultNumberOfDigits 30 2</p>
<p>From now on, for you HPF will always work in a total of 32 decimal digits of precision, and report the top 30 digits, thus two guard digits will be used internally. For example, </p>
<p>pie = hpf('pi')
<br />pie =
<br />3.14159265358979323846264338328</p>
<p>exp(pie - 3)
<br />ans =
<br />1.15210724618790693014572854771</p>
<p>HPF will recall this state the next time you start MATLAB. You can override the default state by specifying a different number of digits though.</p>
<p>hpf('e',12)
<br />ans =
<br />2.71828182846</p>
<p>I've stored values as part of HPF for e and pi that are accurate to 500,000 digits. In fact, those numbers were generated by HPF itself.</p>
<p>Finally, for speed and efficiency, HPF stores all numbers in the form of Migits, which are bundles of decimal digits. This yields a huge bonus in the speed of multiplies, since conv is employed for that purpose. We can see them here:</p>
<p>pie.Migits
<br />ans =
<br /> [3141 5926 5358 9793 2384 6264 3383 2795]</p>
<p>The nice thing is that the use of Migits will be transparent to most users. But if you want a bit more speed in your multiples, then you can get a boost by typing this:</p>
<p>DefaultDecimalBase 6</p>
<p>From now on, HPF will employ base 1000000 migits internally, what I call 6-migits. The only problem is, you will be restricted from using numbers with more than 36000 decimal digits. Speed has a price.</p>
<p>Another nice use of HPF is to extract the exact decimal form that MATLAB uses to store its own numbers. For example, what number does MATLAB REALLY store internally when you type in something like 1.23?</p>
<p>hpf(1.23,55)
<br />ans =
<br />1.229999999999999982236431605997495353221893310546875000</p>
<p>Is HPF complete as it stands? Of course not. HPF currently represents nearly 7000 lines of MATLAB code, in the form of dozens of methods available for the class. As it is, you will find many hundreds of hours of work on my part, over the course of several years. But I've not yet written a huge number of things that might be useful to some people. For example: roots, eig, chol, det, rank, backslash, gamma, etc. And HPF offers no support for complex numbers. Even so, I hope that some will find this useful, if only to learn some of the tricks I've employed in the building thereof. Some of those tricks are described in HPF.pdf.</p>
<p>For example, multiplies are best done in MATLAB by conv. But divides take more work, so here I use a Newton scheme that employs only adds and multiplies, and is quadratically convergent. A similar trick is available for square roots.</p>
<p>Or, look into how my exponential function works. Here I've used a few tricks to enhance speed of convergence of the exponential series. Of course, there are obvious range reduction tricks, but I've gone an extra step there. I also employ a different way of summing the series for exponentials (as well as the sine and cosine series) that minimizes divides.</p>
<p>A lot of thought and research has gone into the methods of HPF. Those thoughts are captured in the HPFMod.pdf file, as enhanced by Derek O'Connor. Many thanks there. HPFMod.pdf is sort of a manual too, for those who want to truly understand the tool.</p>
<p>HPF will probably never be in what I consider to be in a final form, as I am sure there are a few bugs still unfound. Even so, the tool is working quite well on the thousands of tests I have performed. For those of you who try HPF out and do find a bug, please send me an e-mail and I will repair it immediately.</p>John D'Erricohttp://www.mathworks.com/matlabcentral/profile/authors/869215-john-d-erricoMATLAB 7.14 (R2012a)Symbolic Math ToolboxMATLABHPF should work in any MATLAB release that employs the classdef capability for user defined classes.64462223922725false