I have the following nested for loop that uses ismember
to identify the locations where two arrays have the same value. I am doing this so that I can find the data associated with my smaller array tp
(see below).
% 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.
I tried applying what was described here but I'm not sure how to make it work because I am using ismember
and because I'm filling a 3D array.
This works fine using a for
loop but I'd like to make the process faster and I think a parfor
loop is the best option.