I have a cellmatrix that I want to analyse for certain rows in MATLAB. My own solution is pretty bad (see bottom), so I thought someone could give me a hint on how to improve it. I'm pretty sure, I just have to reshape the cell array somehow, but I'm not too sure how to do that.
I have one cell with logical array entries:
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]
Moreover, I have one matrix called Problem that tells me at which rows in "TheCell" I'm interested in (the Problem matrix has stored some certain row indexes of TheCell):
Problem(with M-rows)
For example:
Problem = [3,5,9]
I want to find all cell entries(indexes) of TheCell, where a "1" appears in either of the following positions,:
Critical = [1;2;3;4;5;6]
So for example in row Problem(3), i.e. TheCell{9} the conditions is met at Critical(2), since:
TheCell{Problem(3)}(Critical(2)) == 1
Thus I can make a new entry in my solution matrix:
Solution(counter) = Problem(3)
Finally, I have implemented this in a bad solution, not really efficient.
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