Reputation: 3450
Below code is taken from here.
I am trying to make following change to the code below
If c is not part of the set, plot a white pixel, and if it is part of the set, plot a black pixel.
Use the imshow command to plot your image
% 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.
For 1st point I have no idea what to do.
For completing the 2nd point: when I replace
view(2)
to imshow(2)
I don't get the image just the title, labels
And if I change:
view(2)
to imshow()
I get a 3D plot.
Upvotes: 1
Views: 209
Reputation: 65430
nargin
simply reports the number of input arguments that were passed to a function. You can use a series of if
statements to check what inputs (if any) the user passed and set default values for ones that they did not pass.
It looks like you made it a script instead of a function and hard-coded values for m
, n
and count_max
at the top. In this scenario, the nargin
statements don't matter. However, I would change it back to a function.
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
Then you can call it with the parameters you want
mandelbrot(601, 401, 200)
Upvotes: 1