How to save each iteration of a nested for loop as rows

2 visualizaciones (últimos 30 días)
Elias Lunsford
Elias Lunsford el 5 de Mzo. de 2018
Respondida: Amit el 24 de Abr. de 2018
Hi there,
I am currently attempting to write a code that provides the time stamp(s) in which a cell "spikes" during a specific time of interest within a much longer recording.
for i = 1:size(starttime,1) %starttime is a ix1 matrix of the start times of each period of interest
for j = 1:size(cell,2) %cell is a 1xj array of the time points of each spike for each individual cell
k = find(cell{j} >= starttime(i) & cell{j} <= endtime(i)); %This reports the event, the cell, and the time-stamp of each spike in an array
end
end
The challenge I am facing is saving each iteration of the loop as its own separate row, while reporting the coinciding indexes. What I had hoped for is something along these lines (assuming there were 2 periods of interest and 3 cells, for simplicity's sake):
[1] [1] [2x1 double]
[1] [2] [0x1 double]
[1] [3] [0x1 double]
[2] [1] [ 20]
[2] [2] [0x1 double]
[2] [3] [2x1 double]
In reality, it gives me this:
[1] [3] [0x1 double]
[2] [3] [2x1 double]
I recognize that as it constructs the array it goes by row. Therefore, it is storing each event (i), but not with each of the corresponding iterations of each cell (j). Simply the last iteration.
I have been searching online for a solution I could adapt to this problem, but I have had limited success. I am new to MatLab and would appreciate any suggestions. Thank you in advance.
Cheers,
Elias
  1 comentario
Ameer Hamza
Ameer Hamza el 24 de Abr. de 2018

Are you getting the output from above code? The code you cannot give this output because, in each iteration, you are overwriting the k.

Iniciar sesión para comentar.

Respuestas (1)

Amit
Amit el 24 de Abr. de 2018
p =0;
for i = 1:size(starttime,1)
for j = 1:size(cell,2)
k{p,1} = find(cell{j} >= starttime(i) & cell{j} <= endtime(i));
p = p+1;
end
end
Try this if it solves yours problem.

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by