Could you help me to get started with this complex task?

Here on the pic there is 10 columns, and a lot more rows. The columns represent firing of cells, the rows represent time points. Essentially I need all the time points (rows) when a cell (column) is fired. (represented with a '1' as opposed to '0', I guess this is what we call a logical array). So essentially my task would be to extract all the '1'-s, from all the columns, so from column 1 to column 10. i've been told that I need a for-loop for this, but I dont know how to start this. Could someone help me out? Thanks a lot!

Answers (1)

Abel - your cells variable is a 1440000x10 double array, so loop over each row as
numRows = size(cells,1);
for k=1:numRows
% do something
end
The do something in the above block would be the line or lines of code that would check to see which columns have a one. For example you could do something like
numRows = size(cells,1);
for k=1:numRows
rowData = cells(k,:);
if any(rowData)
% then at least one column within this row contains a one
% and so has fired
fprintf('row %d has at least one column that has fired',k);
end
end
The above code will iterate over each row of cells (you may want to consider renaming this variable) and print a list of all row numbers that have at least one column with a one in it.
The any function determines if any array elements are non-zero (returns true if at least one element is non-zero).

This question is closed.

Asked:

on 16 Jun 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!