Given the following code
clear allclcSP =[1 2 3 4 5 6 9]G= {[1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 6 6 6 6 6 6 3 3 9 9 3 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 ],[ 2 3 2 2 3 4 4 4 5 5 4 4 5 4 6 3 6 6 3 6 3 6 3 3 9 3 9 9 9 9; 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 ]};tt = [20 20 20 20 20 20 20 20 20];for i = 1:size (G,2)result = cell(size(G));for gidx = 1:numel(G) [uval, loc1, ids] = unique(G{gidx}(1, :)); count = accumarray(ids, 1)'; result{gidx} = arrayfun(@(v, s, n, t) [repelem(v, n); s + t.*(1:n)], uval, G{gidx}(2, loc1), count, tt(uval), 'UniformOutput', false);endend VM = cellfun(@(z)cellfun(@(x)sum(x(2,:)<= 120),z),result,'UniformOutput',false);
The code count how many 1-2-3-4-5-6-9 are present in "result" before a value of 120 is reach in each cell of result. For example, considering "result{1, 1}{1, 2}"
the number of 2 before 120 is reached in the second row is 3. so in VM we will have a 3.
If I run the code I obtain as a result :
that means referring to "SP" that In "result{1, 1} " I have five 1, three 2, three 3, three 4, three 5, zero 6 and zero 9.
In case of "result{1, 2}" I dont have 1 inside and so " VM{1, 2}" has 6 element instead of 7. But since 1 is not inside I would like to have
0 3 5 4 3 2 0
instead of
3 5 4 3 2 0
May someone help me in order to modify the code and get the result?
Best Answer