makeimag.m

来自「线性代数实验及MATLAB入门,电子工业出版社出版 陈怀琛 龚杰民合著」· M 代码 · 共 32 行

M
32
字号
function A=makeimag(n,imag,back)
% The command A=makeimag(n,imag,back) lets 
% the user create an n-by-n image with imag 
% and back being the image and background 
% colors,respectively, based on the current 
% colormap. Click with the mouse to toggle 
% to toggle a square between background and 
% image color. Type q when done.
%
% Default image and background colors are 
% used if only one input argument is specified.
subplot(1,1,1)
if nargin==1, imag=27; back=1; end
if nargin==2, back=1; end
A=ones(n)*back;
image(A);axis('square')
while 1
   [x,y,z]=ginput(1);
   if abs(z)=='q'
      break
   elseif (x>=1) &(x<n+1) & (y>=1) &(y<n+1)
      x=fix(x); y=fix(y);
      if A(y,x)==back
         A(y,x)=imag;
      else
         A(y,x)=back;
      end
      image(A); axis('square')
   end
end
close

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?