Error: variable might be used before it is defined.
古いコメントを表示
kindly check screenshot for reference.
回答 (2 件)
Ruchika
2023 年 8 月 11 日
移動済み: Image Analyst
2023 年 8 月 11 日
1 投票
The error message "variable might be used before it is defined" typically occurs when you're trying to use a variable before it has been assigned a value or initialized. This error can often be resolved by ensuring that you define or initialize your variables properly before using them in your MATLAB code. In this code, 'yy3' has been used to initialise 'yy2' before being initialised itself. You want to have an initial value for 'yy3' before using it to resolve this error.
Change this line
yy2 = Pr*(y(4)*y(2)-y(1)*y(5)-Df*yy3-Nb*y(5)*y(7)-Nt*y(5)^2)
to
yy2 = Pr*(y(4)*y(2)-y(1)*y(5)-Df*y(3)-Nb*y(5)*y(7)-Nt*y(5)^2)
% ^^
6 件のコメント
VBBV
2023 年 8 月 11 日
yy3 has been used even before its defined a finite value. Matlab doesnt recognize any undefined variables in a program and throws error as soon as code attempts to call that variable,
Fareeha
2023 年 8 月 11 日
Image Analyst
2023 年 8 月 11 日
Then give yy3 a value before you use it in that line of code.
Torsten
2023 年 8 月 11 日
If you have an initial vector of length 8, you must return a dydt vector of length 8.
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!