insert for loop in the given script

1 次查看(过去 30 天)
Hi, I have this script working for LN = [1], I need to modify it to make it work for LN 1 to n. I was thinking of using a for loop.
%%%%%%%%% estraggo il LAYER numero:[single or multiple]
LN=[1];
%cerco in III colonna i calori di LN
for i=1:Nrow
if isempty(WS{i,3})
idx(i,2)=0;
continue
end
if ismember(WS{i,3},LN)
idx(i,2)=1;
end
end
% %%Prendo solo i wall outer
% for i=1:Nrow
% if isempty(WS{i,5})
% idx(i,3)=0;
% continue
% end
% idx(i,3)=double(strcmp(WS{i,5},'WALL-OUTER'));
% end
%%Prendo TUTTE le linee depositate
for i=1:Nrow
if isempty(WS{i,5})
idx(i,3)=0;
else
idx(i,3)=1;
end
end
%%prendo solo quelli con deposition ==1
for i=1:Nrow
if isempty(WS{i,7})
idx(i,4)=0;
continue
end
idx(i,4)=WS{i,7};
end
idx=prod(idx,2);
figure(1)
axis equal
for i=1:Nrow
if idx(i)==0
continue
end
X=[WS{i,1}(1),WS{i,2}(1)];
Y=[WS{i,1}(2),WS{i,2}(2)];
Z=[WS{i,1}(3),WS{i,2}(3)];
plot3(X,Y,Z,'r');
hold on
end
xlabel('x,[mm]')
ylabel('y,[mm]')
zlabel('z,[mm]')
%%
Xws=[];
Yws=[];
Xmin=75;
Xmax=105;
Ymin=60;
Ymax=90;
Res=0.01;
Xmesh=[Xmin:Res:Xmax];
Ymesh=[Ymin:Res:Ymax];
[Xmesh,Ymesh]=meshgrid(Xmesh,Ymesh);
Xvmesh=reshape(Xmesh,numel(Xmesh),1);
Yvmesh=reshape(Ymesh,numel(Ymesh),1);
XYvmesh=[Xvmesh,Yvmesh];
Amatrix=zeros(size(Xmesh));
for i=1:Nrow
disp(i/Nrow*100);
if idx(i)==0
continue
end
X=[WS{i,1}(1),WS{i,2}(1)];
Y=[WS{i,1}(2),WS{i,2}(2)];
L=((X(2)-X(1))^2+(Y(2)-Y(1))^2)^0.5;
if L>Res
stp=ceil(L/Res);
u=[0:1/stp:1];
xp=X(1)+(X(2)-X(1))*u;
yp=Y(1)+(Y(2)-Y(1))*u;
Xws=[Xws,xp];
Yws=[Yws,yp];
end
end
pause(0.5)
clc
Points=unique((round(1/Res*[Xws',Yws']))*Res,'rows');
figure(2)
hold on
xlim([Xmin Xmax]);
ylim([Ymin, Ymax]);
axis equal
plot(Points(:,1),Points(:,2),'r.')
x=(Points(:,1)-Xmin)/Res;
y=(Points(:,2)-Ymin)/Res;
for i=1:numel(x)
disp(i)
Amatrix(uint64(y(i)),uint64(x(i)))=1;
end
%morphological operation
SE = strel("disk",round((0.35/2)/Res));
Adil = imdilate(Amatrix,SE);
figure(3)
surf(Xmesh,Ymesh,Adil,'linestyle','none')
axis equal
view(2)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by