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

5 vues (au cours des 30 derniers jours)
Jennifer Kurtz
Jennifer Kurtz le 19 Fév 2014
Modifié(e) : Roger Stafford le 19 Fév 2014
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?

Réponse acceptée

Star Strider
Star Strider le 19 Fév 2014
Modifié(e) : Star Strider le 19 Fév 2014
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

Plus de réponses (1)

Roger Stafford
Roger Stafford le 19 Fév 2014
Modifié(e) : Roger Stafford le 19 Fév 2014
A more compact way:
s = Xmult/DataRate;
t = s:s:s*TotalPts;

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by