File Exchange

image thumbnail


version (5.58 KB) by Marco Cococcioni
This functions implements the algorithm of Orthogonal Least Squares.It can be used to rank regressor


Updated 02 Dec 2014

View Version History

View License

[x, ind] = OLS(A,b,r) gives the solution to the least squares problem
using only the best r regressors chosen from the ones present in matrix A.
This function also returns in the vector ind the indexes of the
best r regressors (i.e., the best columns of A to use).

Cite As

Marco Cococcioni (2021). OLS (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Dylan Lynch

Anita Orsetto

I used OLS in my research and worked perfectly. Thank you for sharing.



I would tend to agree with Mr. Shvorob and Mr D'Errico, this is not what I understand orthogonal least-squares. Also, although the code is not as poor as previously seen entries, the general structure is confusing and unnecessarily bloated. In particular, I find the choice to include a demo capability into the function itself, rather than including it as a seperate file, questionable to say the least.

None the less, I'm sure that with a good cleanup, this code will find its uses in some scenarios, if not for the functionality it offers then for its thorough discussion of the theory (although it should probably be moved out of the file to a seperate document).

Fabio Virgulti

xiang qian


John D'Errico

I'll claim that "orthogonal least squares" is far more commonly used in a statistical context to describe a total least squares problem, as Dimitri suggests. Thus the name is indeed misleading to most of the statistics community.

Given that this submission has been placed in the mathematics/linear algebra category, that standard statistical meaning should be presumed.

Giorgio Alessi

I do not agree with review of Dr. Shvorob, since in neural network and fuzzy logic communities "orthogonal least squares" is referred to the problem addressed by the ols.m function written by the author.
I found it very useful. Comments, help and demo is very useful too.

Dimitri Shvorob

This is not what's usually meant by orthogonal least squares, and nobody refers to those as OLS. The programming is simply atrocious: good luck to anyone who tries to follow this 200+ line behemoth.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!