Error assigning variable in loop

조회 수: 1 (최근 30일)
mashtine
mashtine 2014년 11월 13일
댓글: mashtine 2014년 11월 13일
It is beyond me why I cannot figure this out. The debugger points to the line 'wsstd(i,1) = fricvelo.*4;' but I think it has to do with my if statement as even when the condition is failed, a calculation is still done. L(1,1) for instance is -0.393. I am sure my tired eyes just can't find the simple problem.
wsstd = zeros(length(ws),1);
for i = 1:11950;
if L(i,1) >= -500 && L(i,1) <= -50
wsstd(i,1) = fricvelo.*4;
else
wsstd(i,1) = 0;
end
end
  댓글 수: 2
Rick Rosson
Rick Rosson 2014년 11월 13일
편집: Rick Rosson 2014년 11월 13일
  1. Please post the exact and complete error message.
  2. What is the result of typing size(fricvelo) at the command prompt?
mashtine
mashtine 2014년 11월 13일
Hi Rick,
Here is the message:
Subscripted assignment dimension mismatch.
Error in ERA_Suomi_parametrization (line 43)
wsstd(i,1) =
43 wsstd(i,1) = fricvelo.*4
size(fricvelo) is (39928,1) where the #rows is the same as the length(ws)

댓글을 달려면 로그인하십시오.

채택된 답변

Orion
Orion 2014년 11월 13일
You're trying to insert a 39928x1 vector in only one element of wsstd.
size(wsstd(i,1)) == 1 for any i.
So you have a dimension problem.
you can only put a scalar in wsstd(i,1).
You need to change something (like fricvelo(i) ?...)
  댓글 수: 1
mashtine
mashtine 2014년 11월 13일
Wow! How did I not see such an obvious answer! Sorry for waste of time Orion. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by