How can I get a matrix to store all of the for loop results?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
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
0 commentaires
Plus de réponses (1)
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;
0 commentaires
Voir également
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!