How can I create an array of fixed length?
63 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Jos (10584)
il 18 Mar 2014
Maybe you want to pre-allocate z and c like this:
z = zeros(size(z0)) ;
c = zeros(size(z0)) ;
3 Commenti
Akshay Joshi
il 9 Set 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??
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!