У меня есть следующий вложенный цикл for, который использует ismember
для определения местоположений, где два массива имеют одинаковое значение.Я делаю это так, чтобы найти данные, связанные с моим меньшим массивом tp
(см. Ниже).
% xw is a 1xM array of position data
% yw is a 1xN ...
% zw is a 1xP ...
TP = combvec(xw',yw',zw')'; % you must have the deep learning toolbox to use this for the latest version of Matlab 2018b
in = inpolyhedron(f,v,TP); % I would have done inpolyhedron(f,v,Xw,Yw,Zw) where Xw, Yw, and Zw are meshgrids from xw, yw, and zw but doing so exceeds the maximum array size in MatLab.
tp = TP(in,:); Ltp = length(tp);
in3 = zeros(N,M,P);
for l=1:Ltp
for ii=1:M
for jj=1:N
for kk=1:P
if ismember(tp(l,:),TP,'rows')
in3(jj,ii,kk) = ismember(tp(l,:),TP,'rows');
end
end
end
end
end
a = A(in3); % A is a NxMxP array
% a should also be a NxMxP array with the majority of the points being zero, and the points corresponding to tp should be non-zero.
Я пытался применить то, что было описано здесь , но яне уверен, как заставить это работать, потому что я использую ismember
и потому что я заполняю трехмерный массив.
Это прекрасно работает с использованием цикла for
, но я бы хотел ускорить процесс иЯ думаю, что parfor
петля является лучшим вариантом.