此代码正在运行,但需要改进以进行有效计算
anisLoc=[];% Variable sized array
PiezoLoc=[]; % Variable sized array
for i=1:q % Looking in all q
if ~isempty(LayerProp{i}.c)% if c is not empty then
anisLoc=[anisLoc,i];
c{i}=LayerProp{i}.c;
end
if ~isempty(LayerProp{i}.e) % if e is not empty then
% if LayerProp{i}.e(3,3)
PiezoLoc=[i;PiezoLoc];
e{i}=LayerProp{i}.e;
% end
end
end
anisLoc 和 Piezoloc 是可变大小的数组。我将它们设置为最大值 q 但它们会改变大小并且之后无法清空它们,因此它们会从初始代码中产生相同的答案!
anisLoc=zeros(q,1);% Variable sized array
PiezoLoc=zeros(1,q);% Variable sized array
% This loop checks for specific input in data in all
for i=1:q % Looking in all q
if ~isempty(LayerProp{i}.c)% if c is not empty
anisLoc=[i;anisLoc];
c{i}=LayerProp{i}.c;
end
if ~isempty(LayerProp{i}.e) % if e is not empty
% if LayerProp{i}.e(3,3)
PiezoLoc=[PiezoLoc,i];
e{i}=LayerProp{i}.e;
% end
end
end