このコードは機能していますが、効率的な計算のために改善する必要があります
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