![]() |
Exploiting MATLAB's Data Structures |
Is there any pattern to the rank of magic squares?
In this problem
you will create and manipulate the contents of a cell array to find out.
Goal: Create a simple sequence of statements to determine the rank of a series of magic squares. Bar plot the results and see if you notice any patterns. Solve the problem in stages and use a cell array to hold the intermediate results.
Key concepts: creating cell arrays, applying functions to the elements of a cell array, converting a cell array into a numeric array.
Key functions: { }, rank, bar
for i= 50:-1:1 ms{i} = magic(i); endThe loop is run backwards to avoid a preallocation step.
for i=50:-1:1 r(i)= rank(ms{i}); end
bar(r)
for i= 50:-1:1 r(i) = rank(magic(i)); endThe loop is run backwards to avoid a preallocation step.
bar(r)
![]()
Copyright © 1997 The MathWorks,
Inc.
clay@mathworks.com
$Revision$ $Date$