How can I get a matrix to store all of the for loop results?

I would like a final matrix with all of the values of t, but I keep getting an error. Here is my code and the error:
DataRate=4;
TotalPts=14401;
Xmult=.016667;
t=0;
for i=1:TotalPts
t(i)=t+ Xmult/DataRate;
end
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in CE_Alz (line 10) t(i)=t+ Xmult/DataRate;
I understand t, Xmult, and DataRate are all scalar values, but I would like a matrix to be created from the initial t value. What am I doing wrong?

 Accepted Answer

This might do what you want:
DataRate=4;
TotalPts=14401;
Xmult=.016667;
t(1)=0;
for i=2:TotalPts
t(i)=t(i-1) + Xmult/DataRate;
end

More Answers (1)

A more compact way:
s = Xmult/DataRate;
t = s:s:s*TotalPts;

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!