Create new column for data after each iteration of a for loop
Show older comments
Hello, i'm trying to understand how to create a column for data after each iteration of a for loop. I need to run the loop 50 times, and recover the data inside of one matrix. The vector t should change with each iteration of the loop, and this is what I want to record into S matrix as columns... but I cant seem to get it.
if true
% clear all
% lambda, firing rate
lambda = 10;
%total time of simulation 5 seconds
totalTime = 5000; % milliseconds
N = 50; % # trials
spikeTimes = [];
spikeTrain = [];
% Loop
for i = 1:N
for T = 1 : totalTime*1.2
if lambda / 1000 >= -log(rand());
spikeTimes(end + 1) = T;
end
isi = diff(spikeTimes);
t = cumsum(isi)/1000;
end
S = t(:); % <-------- ????
end
end
Any help would be appreciated!!
Accepted Answer
More Answers (1)
Sara
on 1 May 2014
It seems that the vector t could be of different size at each iteration, depending on the if condition. If that's the case, consider using:
S = cell(N,1)
before the for loop and
S{i} = t;
to store t in a cell array.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!