matlab - Making a match-and-append code more efficient without 'for' loop -
I have to match For example, I compare so that it becomes: I could only use it for code a
1 with column 1 st Trying <3> <3> of b
for column and B
to A column 4 Th Add Columns Code>.
A = 1 2 3 4b = 1 2 4 5 4 1 2 3 5 3 1 1 1 2 3 4 5 6 5 < / Code>
A (:, 1)
and B (:, 1: 3)
1
and 3
in A (:, 1)
1
is in B ([1 2 3], 4: end (b): ) From '
to a
s 1 st line 3
2 nd and 4 th in the rows is B (:, 1: 3)
, so attach to B ([2 4], 4: end) '
to A
's 2 nd line
1 2 5 4 5 3 6 5 0 0
and
if
.
< P cleaners aa bin mem memory 2 mem 3a = [1 2; 3 4] B = [1 2 4 5 4; 1 2 3 5 3; 1 1 1 1 2; 3 4 5 6 5] for n = 1: 1: size (A, 1) mem = ismember (b (:, [1: 3]), a (n, 1)); Mem2 = mem (:, 1) + mem (:, 2) + mem (:, 3); Mem3 = find (mem2> 0); AA {N,:} = Hoskat (A (N, :), rehep (B (M3, [4,5]) ', 1, [])); % 'Maximum maximum length = maximum (cellphone (@ (x) digit (x), aa)); Outside = cell 2 erosion (cellphone (@ (x) cat (2, x, zero (1, max length-length (x)), aA, 'uniform output', wrong))
for
and if
is trying to make this code efficient, but no answer could be found.
try it
a = A (:, 1); B = B (:, 1: 3); Z = size (b); B = Repat (B, [1,1, Number (A)]); Ab = repmat (permute (a, [2,3,1]), z); Row2 = mat2cell (sequence (sum (abi == b, 2), [3,1,2]), having (1, number (a))); A.A. = Cellphone (@ (x) (rhesape (b (x> 0,4: end) ', 1, number (b (x> 0,4: end))), line 2,' uniform output ', 0); MaxLenth = Max (Cellphone (@ (X) digit (x), aa)); Outside = cat (2, A, cell 2 matte (cellphone (@ (x) cat (2, x, zero (1, max length-length (x)), AA, 'uniform output', wrong)))
The code below runs at approximately the same time as the code running
a = A (:, 1); b = B (:,, 1: 3); Z = size (b); b = repeat (b, [1,1, number (a)]); ab = repmat (permute (a, [2,3,1] ), Z); Df = permute (zodiac (abb == b, 2), [3,1,2]); aA = sarphen (@ (x) (b (df (, x) & gt; 0,4: end), 1: size (df, 2), 'uniformaptpt', 0); aa = sarphen (@ ) (Reshape (AA {1, x}) 1, Number (AA {1, x}))), 1: size (AA, 2), 'Uniformoptput', 0); MaxLength = Max (array (@ (x) (number (aa {1, x}), 1: size (aa, 2))); Out2 = cell2mat (@ (x, i) ((cat (2, a (i, :), aa {1, x}, zero (1, maximum length-length (aa {1, x})) )), 1: numel (AA), 1: size (A, 1), 'UniformOutput', 0));
Comments
Post a Comment