How can I create an array of fixed length?

61 Ansichten (letzte 30 Tage)
John
John am 17 Mär. 2014
Bearbeitet: Stephen23 am 9 Sep. 2017
UPDATE 1: I fixed my resolution issue, but another problem arose.
I'm currently working on a project for examining the Mandelbrot set. My goal is to draw the Mandelbrot set, center the image on a specific location, and then zoom into it. When zooming I receive the following error code:
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> drawMandelbrot at 20
z = z.^2 + z0;
When k=32, my z0 matrix goes from being 600x600 to 599x600 preventing me from zooming further because I can't add it to z.^2, which stays a constant 600x600.
_____
function [xctr,yctr] = drawMandelbrot(xmin,xmax,ymin,ymax)
res=599/(xmax-xmin);
x = xmin : 1/res : xmax;
y = ymin : 1/res : ymax;
xctr = (xmin + xmax)/2;
yctr = (ymin + ymax)/2;
Length = length(x);
[X,Y]= meshgrid(x,y);
z0 = X + i*Y;
size(z0)
z = zeros(Length,Length);
c = zeros(Length,Length);
depth = 128;
for k = 1 : depth
z = z.^2 + z0;
c(abs(z) < 2) = k;
end
c;
image(c)
axis image
drawnow
colormap(flipud(jet(depth)))
end
______
MAIN
xmin = -2.1;
xmax = .7;
ymin = -1.4;
ymax = 1.4;
[xctr,yctr] = drawMandelbrot(xmin,xmax,ymin,ymax);
xctr_new = -.75;
yctr_new = 0.1;
dx = (xctr_new - xctr)/5;
dy = (yctr_new - yctr)/5;
for j=0:4;
xmin = xmin + dx;
xmax = xmax + dx;
ymin = ymin + dy;
ymax = ymax + dy;
[xctr,yctr] = drawMandelbrot(xmin,xmax,ymin,ymax);
end
delx = (xmax - xmin)/100;
dely = (ymax - ymin)/100;
for k=0:99;
xmin = xmin + .1*k*delx;
xmax = xmax - .1*k*delx;
ymin = ymin + .1*k*dely;
ymax = ymax - .1*k*dely;
k
[xctr,yctr] = drawMandelbrot(xmin,xmax,ymin,ymax);
end
_____
Is there a way to prevent 1 row of z0 from being truncated?
Any help is much appreciated.

Akzeptierte Antwort

Jos (10584)
Jos (10584) am 18 Mär. 2014
Maybe you want to pre-allocate z and c like this:
z = zeros(size(z0)) ;
c = zeros(size(z0)) ;
  3 Kommentare
Akshay Joshi
Akshay Joshi am 9 Sep. 2017
Consider the following scenario: I want my vector size to be 5 i.e. if I try to enter 7 elements in a vector, it should throw some error like "Maximum vector size is 5. You cannot insert more than 5 elements in it."
Is there some way to do so??
Stephen23
Stephen23 am 9 Sep. 2017
Bearbeitet: Stephen23 am 9 Sep. 2017
@Akshay Joshi: You will have to either check the indices before allocating, or check the vector size after allocating.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fractals finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by