Latin Square Matrix
Updated 1 Dec 2017

View License

latsq - Latin Square
M = latsq(N) creates a latin square of size N-by-N containing
the numbers 1 to N. N should be a positive integer.

A latin square of size N is a N-by-N matrix filled with N different
numbers in such a way that each number occurs exactly once in each row
and exactly once in each column. They have applications in the design
of experiments. The output M is also known as the (backward shifted)
circulant matrix of the vector 1:N.

M = latsq(4) % ->
% 1 2 3 4
% 2 3 4 1
% 3 4 1 2
% 4 1 2 3

% latin square of categories
C = {'goat','cabbage','wolf'}
idx = latsq(numel(C))
M = C(idx)

% Randomized latin square
V = randperm(6)
M = V(latsq(numel(V)))

See also magic, gallery,
ballatsq, circulant, slm (file Exchange)

More information:

Cite As

Jos (10584) (2024). latsq(N) (, MATLAB Central File Exchange. Retrieved .

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

Inspired: latin cube

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

added some additional help ; removed second output

updated hellp

fixed error in randomization