フィルターのクリア

Assigning a value to a vector in a for loop

5 ビュー (過去 30 日間)
Kim
Kim 2014 年 9 月 14 日
コメント済み: Star Strider 2014 年 9 月 14 日
I'm trying to assign individual times to a vector 'toa' in a loop using:
for jj = 1:nvar
ktau = jj * tau0;
toa(jj) = jj * tau0;
{buncha calcs}
end
I use ktau in following equations, and I want to keep a vector of all the times used.
When I try to run the function I get: In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in alvarQ (line 115) toa(jj) = jj.*tau0; % this was time calc above
Why is that? Shouldn't that work?
Thanks, Kim

回答 (3 件)

Image Analyst
Image Analyst 2014 年 9 月 14 日
Evidently tau0 is a vector, not a scalar, so the product of jj*tau0 is also a vector. You can't stuff a vector of multiple elements into a single element of toa. Maybe you meant tau0(jj)???? What does "whos ktau" show?

Star Strider
Star Strider 2014 年 9 月 14 日
Is ‘tau0’ a vector or a scalar?
Otherwise, your ‘{buncha calcs}’ could be the problem. Are you doing anything to ‘toa’ or ‘tau0’ in them?

Kim
Kim 2014 年 9 月 14 日
Y'all, thanks for the help. Based on what you said I went and looked at tau0. It was supposed to be a scalar. I'd read it out of a file header. However it was stored as text i.e. '9.9998e-6' instead of 9.9998e-6.
Quick use of str2num straightened me out, and things ran fine.
  1 件のコメント
Star Strider
Star Strider 2014 年 9 月 14 日
Glad you got that sorted out!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by