# Difference between revisions of "Pad array"

Jump to navigation
Jump to search

(Created page with "{{Function |name=pad_array |desc=Pads an array with zeroes in a similar way to padarray in MATLAB. |cat=Helper functions |upd=July 18th,...") |
|||

Line 16: | Line 16: | ||

* <tt>DIR</tt>: An integer specifying whether to prepend or postpend the zeroes onto <tt>ARR</tt>. 0 means to prepend, 1 means to postpend, and any other number will throw an error. | * <tt>DIR</tt>: An integer specifying whether to prepend or postpend the zeroes onto <tt>ARR</tt>. 0 means to prepend, 1 means to postpend, and any other number will throw an error. | ||

==Examples== | ==Examples== | ||

− | + | A basic example of how pad_array works. | |

<syntaxhighlight> | <syntaxhighlight> | ||

>> arr = [1,2,3,4]; | >> arr = [1,2,3,4]; |

## Latest revision as of 16:22, 18 July 2018

pad_array | |

Pads an array with zeroes in a similar way to padarray in MATLAB. | |

Other toolboxes required | none |
---|---|

Function category | Helper functions |

This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function. |

` pad_array` is a function that takes an array and either prepends or postpends a number of zeroes specified by the function call.

## Syntax

`BIN = pad_array(ARR, PAD_NUM, DIR)`

## Argument descriptions

`ARR`: The array which will have zeroes padded onto it.`PAD_NUM`: The number of zeroes to either prepend or postpend onto`ARR`. This must be a non-negative integer.`DIR`: An integer specifying whether to prepend or postpend the zeroes onto`ARR`. 0 means to prepend, 1 means to postpend, and any other number will throw an error.

## Examples

A basic example of how pad_array works.

```
>> arr = [1,2,3,4];
>> pad_array(arr, 2, 0)
ans =
0 0 1 2 3 4
>> pad_array(arr, 2, 1)
ans =
1 2 3 4 0 0
```

## Notes

This function is only meant to simplify code within other functions without the need to install the image processing package of MATLAB or Octave-Forge. Note that this function only pads with zeroes. If other numbers are required, please use the `padarray' function within the image processing toolbox of MATLAB or Octave-Forge.

## Source code

Click on "expand" to the right to view the MATLAB source code for this function.