cwdaniels
cwdaniels

Reputation: 71

Using a for loop, I need to save data that is generated in a matrix

Below you will find my code. What I need, is for every loop to save the data that is created in A_wm into TOTAL. I keep getting the error: Subscripted assignment dimension mismatch. I realize this means that the code on the right hand side of the equals sign for TOTAL is not the same size of TOTAL. However, total is preallocated and needs to remain that size. (It has the same # of columns as A_wm but not rows). My idea is that every iteration will save the data in A_wm to a new row in TOTAL. Any suggestions?

mu = .5; 
LAMMDA = 2; 
t = 1:61; 
T0 = 0;
trials = 1:50; 

TOTAL = zeros(50,61); 

for i = trials
    %Clock: Pacemaker ---> Accumulator
    D = t - T0; %effectual switch closure duration
    A_wm = -mu*log(1-rand(1)) * LAMMDA * D;
    TOTAL(i,:) = repmat(A_wm,size(TOTAL,1),1);   
end

Upvotes: 0

Views: 431

Answers (1)

Shai
Shai

Reputation: 114786

why do you repmat A_wm? try assigning without repmat:

TOTAL(i,:) = A_wm;

Upvotes: 2

Related Questions