Count how many element are inside each cell af a cell array on the basis of an array
Show older comments
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?
6 Comments
Is there a particular need to have a 1x2 cell array with two 1x6 cell arrays nested inside it? Why not just have one 2x6 cell array without any nesting (which would simplify the code)?
You do not explain what role SP has in your algorithm: perhaps it corresponds to your "considering element 1.." and "take the element 2...", but as none of the cell arrays have 9 elements, there is no way to "consider element 9" if it does not exist. You need to explain SP better.
"SP as well as V are fixed and obtained from a previous code."
Sure, that is nice.
"Do you wanna see the previous code?"
I have no idea what "wanna" means, but it sounds rather painful, so I will decline your offer.
But I do want to know what role SP plays in your algorithm, which so far you have not explained. For example, in your question SP occurs just once (to define it and then never refer to it again). In your comments you explain that SP contains attributes... which is lovely, but it is not what I asked about. Perhaps SP bears no relevance, which so far appears to be the case.
Here is my question again, in slightly different words:
How do you use the values of SP in the algorithm that you ask about in your question?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!