Create arrays based on cell arrays
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
luca
el 24 de Sept. de 2019
Comentada: luca
el 7 de Oct. de 2019
Hi,
given the following code
clear all
clc
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 ],[1 1 1 1 1 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 155 160 165 170 175]};
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);
end
end
I want to derive X arrays from the values contained in "result". The number x is equal to the number of cell contained in result
Each array should contain the number of times the different elements are repeated in each cell, but till we reach a value lower than 120 in the second raw of each cell.
Let's see better what I mean.
Consider the first cell
so
now consider the first cell
I want to collect all the values of 1 that has a value in the second raw lower equal than 120. in this case N1=5
Considering the 5th cell
in this case N5=3, cause at the 4th value we find 140>120.
so the first array that we want to obtain for the first 1*7 cell of G will be
V1= [ 5 3 3 3 3 0 0]
May someone help me to get these arrays ?
0 comentarios
Respuesta aceptada
Adam Danz
el 24 de Sept. de 2019
V = cellfun(@(z)cellfun(@(x)sum(x(2,:)<=120),z),result,'UniformOutput',false);
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!