这段程序中elsif结构过于复杂,想精简
if w2(i,j)==1
invoke(component,'new',strcat('solid1',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid1',num2str(i),'_',num2str(j));
Selected_Name='component1:solid1';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);invoke(component,'new',strcat('solid1',num2str(i),'_',num2str(j)));
elseif w2(i,j)==2
invoke(component,'new',strcat('solid2',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid2',num2str(i),'_',num2str(j));
Selected_Name='component1:solid2';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==3
invoke(component,'new',strcat('solid3',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid3',num2str(i),'_',num2str(j));
Selected_Name='component1:solid3';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==4
invoke(component,'new',strcat('solid4',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid4',num2str(i),'_',num2str(j));
Selected_Name='component1:solid4';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==5
invoke(component,'new',strcat('solid5',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid5',num2str(i),'_',num2str(j));
Selected_Name='component1:solid5';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==6
invoke(component,'new',strcat('solid6',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid6',num2str(i),'_',num2str(j));
Selected_Name='component1:solid6';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==7
invoke(component,'new',strcat('solid7',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid7',num2str(i),'_',num2str(j));
Selected_Name='component1:solid7';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
elseif w2(i,j)==8
invoke(component,'new',strcat('solid8',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid8',num2str(i),'_',num2str(j));
Selected_Name='component1:solid8';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
end
end
end
这样?:
if w2(i,j)==1
invoke(component,'new',strcat('solid1',num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat('solid1',num2str(i),'_',num2str(j));
Selected_Name='component1:solid1';
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);invoke(component,'new',strcat('solid1',num2str(i),'_',num2str(j)));
else
invoke(component,'new',strcat(['solid',num2str(w2(i,j))],num2str(i),'_',num2str(j)));
x = (j-1)*p; y = (1-i)*p; z = 0;
Rep=1;
what = 'Shape';
how = 'Translate';
Destination_Name = strcat(['solid',num2str(w2(i,j))],num2str(i),'_',num2str(j));
Selected_Name=['component1:solid',num2str(w2(i,j))];
transform = invoke(mws, 'Transform');
Transform (transform , Selected_Name, x, y, z, Rep, Destination_Name,what,how);
end