我需要生成具有给定属性的所有n阶的矩形矩阵。
我正在使用Matlab2012b。你能帮我解决这个问题吗?
我试图把它写下来。它需要很长的for循环序列。任何更简单的技术?
答案 0 :(得分:3)
试试这个:
N = 4; %// matrix size
M = (N^2-N)/2; %// number of values to fill in each matrix
P = 2^M; %// number of matrices
x = dec2bin(0:P-1)-'0'; %// each row contains the values of a matrix, "packed" in a vector
result = NaN(N,N,P); %// preallocate
for k = 1:P
result(:,:,k) = squareform(x(k,:)); %// unpack values
end
矩阵为result(:,:,1)
,result(:,:,2)
等。