I quite often find myself using `meshgrid`

or `ndgrid`

, let's say we want to compute a mandelbrot image, then we initialize e.g.

```
[x,y]=meshgrid(-2:1e-2:1,-1:1e-2,1)
```

Now for the mandelbrot set we need another matrix `c`

of the size of `x`

and `y`

but initialized with zeros. This can easily be done by writing:

```
c=x*0;
```

You can also initialize it to another value:

```
c=x*0+3;
```

But you can actually save some bytes by just adding another dimension in `meshgrid/ndgrid`

:

```
[x,y,c]=meshgrid(-2:1e-2:1,-1:1e_2,1, 0); %or for the value 3
[x,y,c]=meshgrid(-2:1e-2:1,-1:1e_2,1, 3);
```

And you can do this as often as you want:

```
[x,y,c1,c2,c3,c4,c5]=meshgrid(-2:1e-2:1,-1:1e_2,1, 1,pi,exp(3),1e5,-3i)
```

Memoizing functions in MatLab – mbomb007 – 2016-10-26T15:15:48.440

3

Related, but not a duplicate: Tips for golfing in Octave

– Dennis Jaheruddin – 2014-01-29T10:15:46.577