Are you getting the output from above code? The code you cannot give this output because, in each iteration, you are overwriting the k.
How to save each iteration of a nested for loop as rows
조회 수: 1 (최근 30일)
이전 댓글 표시
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개)
Amit
2018년 4월 24일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!