【问题标题】:How to plot black and white color picture mandelbrot plot如何绘制黑白彩色图片曼德布罗图
【发布时间】:2016-04-23 12:34:02
【问题描述】:

以下代码取自here

我正在尝试对下面的代码进行以下更改

如果 c 不是集合的一部分,则绘制一个白色 像素,如果它是集合的一部分,则绘制一个黑色像素。

使用 imshow 命令绘制图像

%  Parameters:
%    Input, integer M, the number of pixels in the X direction.
%    Input, integer N, the number of pixels in the Y direction.
%    Input, integer COUNT_MAX, the number of iterations.  While 10 or
%    20 is a reasonable value, increasing COUNT_MAX gives a sharper image.
%
    m=601; 
    n=401;
    count_max = 200;

  %Change the range of x's and y's here 
  x_max =   1;
  x_min = - 2;
  y_max =   1;
  y_min = - 1;

%  Create an array of complex sample points in [x_min,x_max] + [y_min,y_max]*i.
%
  I = ( 1 : m );
  J = ( 1 : n );
  X = ( ( I - 1 ) * x_max + ( m - I ) * x_min ) / ( m - 1 );
  Y = ( ( J - 1 ) * y_max + ( n - J ) * y_min ) / ( n - 1 );
  [ Zr, Zi ] = meshgrid ( X, Y );
  C = complex ( Zr, Zi );
%
%  Carry out the iteration.
%
  epsilon = 0.001;

  Z = C;
  ieps = 1 : numel ( C );

  %Iterate through 1 to maximum no. of iterations
  for i = 1 : count_max
    Z(ieps) = Z(ieps) .* Z(ieps) + C(ieps); 
    W(ieps) = exp ( - abs ( Z(ieps) ) );
    ieps = ieps ( find ( epsilon < W(ieps) ) );
  end
%
%  Display the data.
%
  d = log ( abs ( Z ) );
  t = delaunay ( Zr, Zi );
%
%  To see individual pixels, use 'flat' color.
%
 h = trisurf ( t, Zr, Zi, d, 'FaceColor', 'flat', 'EdgeColor', 'flat' );
%
%  h = trisurf ( t, Zr, Zi, d, 'FaceColor', 'interp', 'EdgeColor', 'interp' );

  view ( 2 )
  axis equal
  axis on
  title_string = sprintf ( 'Mandelbrot set, %d x %d pixels, %d iterations', ...
    m, n, count_max );
  title ( title_string )
  xlabel ('Real Axis');
  ylabel ('Imaginary Axis');
%  Terminate.

对于第一点,我不知道该怎么做。

为了完成第二点: 当我替换

view(2)imshow(2) 我没有得到图片,只有标题和标签

如果我改变:

view(2)imshow() 我得到一个 3D 绘图。

【问题讨论】:

    标签: matlab matplotlib plot mandelbrot


    【解决方案1】:

    nargin 只报告传递给函数的输入参数的数量。您可以使用一系列if 语句来检查用户传递了哪些输入(如果有),并为他们未传递的输入设置默认值。

    看起来您将其设置为脚本而不是函数,并在顶部硬编码了 mncount_max 的值。在这种情况下,nargin 语句无关紧要。但是,我会将其 back 更改为函数。

    function mandelbrot ( m, n, count_max )
        %// If no input were provided use m = 101
        if ( nargin == 0 )
            m = 101;
        end
    
        %// If the second input wasn't provided, set it equal to m
        if ( nargin <= 1 )
            n = m;
        end
    
        %// If the third input wasn't provided, set count_max = 20
        if ( nargin <= 2 )
            count_max = 20;
        end
    
        %// Other stuff here
    end
    

    然后你可以用你想要的参数调用它

    mandelbrot(601, 401, 200)
    

    【讨论】:

    • 哦,我明白了,谢谢你的解释我现在明白了nargin的使用你能帮我解决前两个要求吗?
    • @newguy 它解决了您的最后一个问题。你为什么要尝试用任何东西替换view(2)imshowview(2)无关
    • @newguy 您需要在每个帖子中问 一个 问题。您能否将您的问题修改为仅询问 nargin,然后我们可以在新问题中解决您的其他问题之一?
    • 我明白这一点,但我的主要要求是前两点,我必须等待大约 1 小时才能提出另一个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多