swap.m

Randomly shuffles a binary matrix while keeping row and column sums the same as the original matrix.
1.4K Downloads
Updated 1 Apr 2003

No License

This function carries out a swap algorithm as described in Stone and Roberts (1990), Oecologia 85:74-79. The data matrix must be organized with sites (islands) as rows, and species as columns. The function only works with binary matrices (but can be easily modified to convert abundance matrices).

"Swapping" randomly shuffles a binary matrix while keeping the row and column sums the same.

To call the function, send the data matrix and the number of swaps you wish to have carried out: swap(matrix,1000). The function returns the shuffled matrix. For each swap, the function randomly identifies two rows and columns such that:

[...0...1..;
..........;
...1...0..]

and then switches (swaps) the 0's and 1's within the columns.

Written by Brice X. Semmens (semmens@u.washington.edu), 03/26/03
Comments and modifications/improvements welcome.

Cite As

Brice Semmens (2024). swap.m (https://www.mathworks.com/matlabcentral/fileexchange/3205-swap-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R11.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0