for loop return empty struct

4 ビュー (過去 30 日間)
Teerapong Poltue
Teerapong Poltue 2021 年 1 月 18 日
コメント済み: Teerapong Poltue 2021 年 1 月 18 日
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 ?

回答 (1 件)

Walter Roberson
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
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.
  3 件のコメント
Walter Roberson
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?
Teerapong Poltue
Teerapong Poltue 2021 年 1 月 18 日
I want unit cell to be able to change the size so I can find different surface area as unit cell size change.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeScalar Volume Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by