Count how many element are inside each cell af a cell array on the basis of an array
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
luca
el 15 de Oct. de 2019
Comentada: luca
el 16 de Oct. de 2019
Hi given a cell array
V={{[1,1,1,1;25,45,70,90],[2,2,2,2;78,112,146,180],[3,3,3,3;93,127,161,195],[4,4;70,100],[6;85],[9,9;85,110]},{[],[2,2,2,2;73,107,141,175],[3,3,3,3;83,117,151,185],[4,4,4,4;65,85,105,125],[6;85],[9,9,9;80,105,130]}};
and an array
SP= [1 2 3 4 6 9]
I want to create a matrix M that has as many rows as the cell in V (in this case 2)
CONSIDERING THE FIRST CELL:
Inside the row of M how want to count how many elements are present in each cell of the same type, and that cannot exceed a value of 80 (<80) referring to the second raw of each cell.
considering element 1 in V{1,1} that occupies V{1,1}{1,1}
In this case the number of 1 that do not exceed 80 is 3.
take the element 2
is just 1.
Doing the same for all the elements and cells i ontain M:
M= [3 1 0 1 0 0; 0 1 0 1 0 1]
May someone help me with the code?
Respuesta aceptada
Stephen23
el 16 de Oct. de 2019
Editada: Stephen23
el 16 de Oct. de 2019
>> C = vertcat(V{:});
>> X = ~cellfun('isempty',C);
>> F = @(x)sum(x(2,:)<=80);
>> M = zeros(size(C));
>> M(X) = cellfun(F,C(X))
M =
3 1 0 1 0 0
0 1 0 1 0 1
Nothing in your question or comments seems to require SP, so I have ignored it.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!