用Hadamard矩阵模式绘制圆圈

时间:2018-03-18 11:30:04

标签: matlab

我想在8,16和32的Hadamard矩阵模式中绘制圆圈。到目前为止,我有一个用于绘制2D圆阵列的代码。

%Plotting  an N by N arrays of circles
clc; clear;
n_circles = 8;                    % Define the number of circles to be plotted
R = 40;                      % Define the radius of the basic circle
Len=1024;
M=zeros(Len);               % Create the hole mask

% Get the indices of the points inside the basic circle
M0 = zeros(2*R+1);             % Initialize the basic mask
I = 1:(2*R+1);             % Define the x and y coordinates of the basic mask
x = (I - R)-1;
y = (R - I)+1;
[X,Y] = meshgrid(x,y);      % Create the mask
A = (X.^2 + Y.^2 <= R^2);   
[xx,yy]=ind2sub(size(M0),find(A == true));  

%plot
for ii=1:n_circles
    for jj=1:n_circles
      MidX=Len/2+(ii-n_circles/2-0.5)*(2*R);
      MidY=Len/2+(jj-n_circles/2-0.5)*(2*R);
%       [MidX MidY]
      M(sub2ind(size(M),MidX+xx-R-1,MidY+yy-R-1))=1;
    end
end
figure(1)
imshow(M)

我搜索了如何绘制Hadamard矩阵,并从Mathworks文档中the hadamard matrix function

H = hadamard(n) 

返回n阶的Hadamard矩阵。如何将其合并到我的原始代码中,以便最终结果将生成以Hadamard模式绘制的圆形图像,其中值1表示圆,而-1表示空(无圆)?

谢谢,

1 个答案:

答案 0 :(得分:1)

在开头添加

H = hadamard(n_circles);

并且循环内部变为:

M(sub2ind(size(M),MidX+xx-R-1,MidY+yy-R-1))=H(ii,jj);