Matrices won't take values and output from function.
Mostra commenti meno recenti
if true
function[finX,finY] = recurse(A,B,finX,finY)
for j=1:4
temp1 = A(j,:);
temp2 = B(j,:);
split(temp1, temp2, finX, finY);
end
function split(X,Y, finX, finY)
wid = abs((X(4)- X(1))/2);
if wid >= (1/8);
finalX = zeros(4,4);
finalY = zeros(4,4);
keep = 0;
for i=1:4
x1 = X(i);
y1 =Y(i);
if (x1^2 + y1^2 <= 4)
keep = keep +1;
end
end
if keep == 1 || 2 || 3
finalX(1,1) = X(1);
finalY(1,1) = Y(1);
finalX(1,2) = X(1);
finalY(1,2) = Y(1)+wid;
finalX(1,3) = X(1)+wid;
finalY(1,3) = Y(1)+wid;
finalX(1,4) = X(1)+wid;
finalY(1,4) = Y(1);
finalX(2,1) = X(1);
finalY(2,1) = Y(1)+wid;
finalX(2,2) = X(1);
finalY(2,2) = Y(1)+2*wid;
finalX(2,3) = X(1)+wid;
finalY(2,3) = Y(1)+2*wid;
finalX(2,4) = X(1)+wid;
finalY(2,4) = X(1)+wid;
finalX(3,1) = X(1)+wid;
finalY(3,1) = Y(1)+wid;
finalX(3,2) = X(1)+wid;
finalY(3,2) = Y(1)+2*wid;
finalX(3,3) = X(1)+2*wid;
finalY(3,3) = Y(1)+2*wid;
finalX(3,4) = X(1)+2*wid;
finalY(3,4) = Y(1)+wid;
finalX(4,1) = X(1)+wid;
finalY(4,1) = Y(1);
finalX(4,2) = X(1)+wid;
finalY(4,2) = Y(1)+wid;
finalX(4,3) = X(1)+2*wid;
finalY(4,3) = Y(1)+wid;
finalX(4,4) = X(1)+2*wid;
finalY(4,4) = Y(1);
recurse(finalX, finalY, finX, finY);
elseif keep == 4
finX = [finX;X]; %won't change
finY = [finY;Y]; %won't change
else
end
end
end
end
end
I'm building a square mesh over a circle of radius 2. Giving the function two 4x4 matrices which contains the X and Y coordinates of the 4 vertexes of 4 squares, I remove the first row (first square) from each matrix and then in "split" I test each point to see if it is contained in the circle. If 1-3 points are contained, I split that square into 4 smaller ones and call recurse on those matrices. If 4 points are contained, I'm trying to add the rows I pulled out (so that square) into finX and finY. In the end, It is supposed to return finX and finY with each row being the coordinates of a square that will belong in the mesh.
I cannot for the life of me figure out why none of the values will go into finX or finY when they keep (my vertex counter) is equal to 4. It just.. skips it.
I tried to "Run and Advance" with breakpoints but I get the error :
function [finX,finY] = recurse1(A,B,finX,finY) | Error: Function definitions are not permitted in this context.
Not really sure why. I think because I have variables and I'm supposed to run it in the main console, but I don't know how to check breakpoints when I run it there.
Risposta accettata
Più risposte (1)
Christyn Phillippi
il 28 Mar 2014
1 Commento
Star Strider
il 28 Mar 2014
Modificato: Star Strider
il 28 Mar 2014
My pleasure (albeit serendipitously)!
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!