## Remove xticks but keep xticklabels in MATLAB

Try modifying the TickLength property: set(gca, ‘Ticklength’, [0 0])

## Skipping outputs with anonymous function in MATLAB

There’s no way I know of within the expression of the anonymous function to have it select which output to return from a function with multiple possible output arguments. However, you can return multiple outputs when you evaluate the anonymous function. Here’s an example using the function MAX: >> data = [1 3 2 5 … Read more

## How to work with Unix timestamps in Matlab?

How about date = datestr(unix_time/86400 + datenum(1970,1,1)) if unix_time is given in seconds, unix_time/86400 will give the number of days since Jan. 1st 1970. Add to that the offset used by Matlab’s datenum (datenum(0000,1,1) == 1), and you have the amount of days since Jan. 1st, 0000. This can be easily converted to human-readable form … Read more

## 3D curvefitting

To fit a curve onto a set of points, we can use ordinary least-squares regression. There is a solution page by MathWorks describing the process. As an example, let’s start with some random data: % some 3d points data = mvnrnd([0 0 0], [1 -0.5 0.8; -0.5 1.1 0; 0.8 0 1], 50); As @BasSwinckels … Read more

## Multiple plots in one figure

Well, there are a few ways how multiple data series can be displayed in the same figure. I will use a little example data set, together with corresponding colors: %% Data t = 0:100; f1 = 0.3; f2 = 0.07; u1 = sin(f1*t); cu1 = ‘r’; %red u2 = cos(f2*t); cu2 = ‘b’; %blue v1 … Read more

## Display matrix with row and column labels

Matlab has a function called printmat in the Control Systems toolbox. It’s in the directory “ctrlobsolete“, so we can assume that it is considered “obsolete”, but it still works. The help text is: >> help printmat printmat Print matrix with labels. printmat(A,NAME,RLAB,CLAB) prints the matrix A with the row labels RLAB and column labels CLAB. … Read more

## How to apply a low-pass or high-pass filter to an array in Matlab?

Look at the filter function. If you just need a 1-pole low-pass filter, it’s xfilt = filter(a, [1 a-1], x); where a = T/τ, T = the time between samples, and τ (tau) is the filter time constant. Here’s the corresponding high-pass filter: xfilt = filter([1-a a-1],[1 a-1], x); If you need to design a … Read more