for loop return empty struct

2 views (last 30 days)
Teerapong Poltue on 18 Jan 2021
Commented: Teerapong Poltue on 18 Jan 2021
syms x y z
thickness = 0.1:0.01:0.30;
unitcellsize = 1:0.1:6;
num = max(size(unitcellsize));
a = 0:step:unitcellsize;
b = 0:step:unitcellsize;
c = 0:step:unitcellsize;
[X,Y,Z] = meshgrid(a,b,c);
f = @(x,y,z,unitcellsize) 2.*(cos((2.*pi.*x)./unitcellsize).* cos((2.*pi.*y)./unitcellsize) + cos((2.*pi.*y)./unitcellsize).* cos((2.*pi.*z)./unitcellsize) + cos((2.*pi.*z)./unitcellsize).*cos((2.*pi.*x)./unitcellsize)) - (cos((4.*pi.*x)./unitcellsize)+cos((4.*pi.*y)./unitcellsize)+cos((4.*pi.*z)./unitcellsize));
for ii = 1:num;
V{ii} = f(X,Y,Z,unitcellsize(ii));
end
for i = 1:num;
co(i) = isosurface(a,b,c,V{i},0) ;
end
It turns out that 'co' not return all the loop it stoped some how. I don't know why ?

Walter Roberson on 18 Jan 2021
syms x y z
thickness = 0.1:0.01:0.30;
unitcellsize = 1:0.1:6;
num = max(size(unitcellsize));
step = 0.5;
a = 0:step:unitcellsize;
b = 0:step:unitcellsize;
c = 0:step:unitcellsize;
[X,Y,Z] = meshgrid(a,b,c);
f = @(x,y,z,unitcellsize) 2.*(cos((2.*pi.*x)./unitcellsize).* cos((2.*pi.*y)./unitcellsize) + cos((2.*pi.*y)./unitcellsize).* cos((2.*pi.*z)./unitcellsize) + cos((2.*pi.*z)./unitcellsize).*cos((2.*pi.*x)./unitcellsize)) - (cos((4.*pi.*x)./unitcellsize)+cos((4.*pi.*y)./unitcellsize)+cos((4.*pi.*z)./unitcellsize));
for ii = 1:num
V{ii} = f(X,Y,Z,unitcellsize(ii));
end
for i = 1:num
thisco = isosurface(a,b,c,V{i},0);
co(i) = thisco;
if isempty(thisco) || isempty(thisco.vertices)
minV = min(V{i},[],'all');
maxV = max(V{i},[],'all');
fprintf('iteration #%d, empty isosurface, V range is %f to %f\n', i, minV, maxV);
break
end
end
iteration #26, empty isosurface, V range is 0.010885 to 3.000000
Which is to say that you are getting empty structure entries because you are asking for isosurface at level 0 for data that does not include 0.
You are dividing by larger and larger numbers as you go, so you should expect that your f values will at some point become only slightly wavy around some constant offset.
Teerapong Poltue on 18 Jan 2021
I want unit cell to be able to change the size so I can find different surface area as unit cell size change.