Modify the array of large cells to find specific rows that satisfy the condition in MATLAB

I have a cellmatrix that I want to parse for specific rows in MATLAB. My own solution is pretty bad (see below), so I thought that someone could give me a hint on how to improve it. I'm sure I just need to somehow change the array of cells, but I'm not too sure how to do it.

I have one cell with elements of a logical array:

TheCell{with N-rows cell}(Logical Array with varying length, but max 24 entries)

For example:

TheCell{1} = [0,1,0,1,0,0,0,0,0,1,0]
TheCell{2} = [0,0,0,0]
...
TheCell{9} = [0,1,0,0,0,0,0]

In addition, I have one matrix called “Problem” that tells me which lines in “TheCell” interest me (the problem matrix stores some specific TheCell line indexes):

Problem(with M-rows)

For example:

Problem = [3,5,9]

() TheCell, "1" :

Critical = [1;2;3;4;5;6]

, , (3), .. TheCell {9} Critical (2), :

TheCell{Problem(3)}(Critical(2)) == 1

, :

Solution(counter) = Problem(3)

, , .

Critical = [1;2;3;4;5;6];
Solution = [];
counter = 1;
for i = 1:length(Problem)
   Row = Problem(i);
   b = length(TheCell{Row})
   for k = 1:length(Critical)
        if k > b
           break;
        end  
        if TheCell{Row}(Critical(k))==1
            Solution(counter) = Row;
            counter = counter+1;
            break;
        end
    end
end
+4
1
Critical = 6;
find(cellfun(@(x)any(x(1:min(Critical,end))), TheCell))

Critical , 1,

Critical = [2,4,5];
find(cellfun(@(x)any(x(min(Critical,end))), TheCell))

, TheCell, , , , , false.

TheMatrix = false(9,24);

%// You would generate this more sensibly in your process
TheMatrix(1,1:11) = [0,1,0,1,0,0,0,0,0,1,0]
TheMatrix(2,1:4) = [0,0,0,0]
...
TheMatrix(9,1:7) = [0,1,0,0,0,0,0]

:

find(any(TheMatrix(:,Critical),2))
+3

Source: https://habr.com/ru/post/1627975/


All Articles