for loop return empty struct
2 ビュー (過去 30 日間)
古いコメントを表示
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/491845/image.png)
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 1 月 18 日
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
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.
3 件のコメント
Walter Roberson
2021 年 1 月 18 日
a = 0:step:unitcellsize;
b = 0:step:unitcellsize;
c = 0:step:unitcellsize;
but unitcellsize is a vector, and when you use a vector as a bound, the first element of the vector is used. So a and b and c are not increasing as unitcellsize increases: they are stuck at 1. Is that what you want?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!