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

조회 수: 5 (최근 30일)
Jennifer Kurtz
Jennifer Kurtz 2014년 2월 19일
편집: Roger Stafford 2014년 2월 19일
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?

채택된 답변

Star Strider
Star Strider 2014년 2월 19일
편집: Star Strider 2014년 2월 19일
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

추가 답변 (1개)

Roger Stafford
Roger Stafford 2014년 2월 19일
편집: Roger Stafford 2014년 2월 19일
A more compact way:
s = Xmult/DataRate;
t = s:s:s*TotalPts;

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by