フィルターのクリア

Array indices must be positive integers or logical values

3 ビュー (過去 30 日間)
Aneesa Shahbaz
Aneesa Shahbaz 2021 年 4 月 12 日
コメント済み: Aneesa Shahbaz 2021 年 4 月 14 日
U0 = 0.1;
V0 = 0.5;
W = 1;
t = 1;
x = linspace(0,3); % create linear spacing in x-direction
y = linspace(0,3); % create linear spacing in y-direction
XX = zeros(length(x),length(y));
YY = zeros(length(x),length(y));
%looping in i and j-directions
for i = 1:length(x)
for j = 1:length(y)
%create x & y space
XX(i,j) = x(i);
YY(i,j) = y(j);
psi(i,j) = ((U0*V0)./W)*cos(W(t-YY(i,j)./V0))-V0*XX(i,j);
I get an error message of
Array indices must be positive integers or logical values.
Error in psi(i,j) = ((U0*V0)./W)*cos(W(t-YY(i,j)./V0))-V0*XX(i,j);

採用された回答

Daniel Pollard
Daniel Pollard 2021 年 4 月 12 日
You wrote
psi(i,j) = ((U0*V0)./W)*cos(W(t-YY(i,j)./V0))-V0*XX(i,j);
Try
psi(i,j) = ((U0*V0)./W)*cos(W*(t-YY(i,j)./V0))-V0*XX(i,j);
W is not a vector or matrix, so calling W(t-YY(i,j)./V0) won't return anything sensible. I think you mean to multiply W by the bracketed term in the cos.
Side note: i and j make terrible variable names in Matlab. They already have a built in value of the complex unit, so redefining that is likely to throw errors further down the line. I tend to use ii, jj or k for loop indices to avoid this problem.

その他の回答 (0 件)

カテゴリ

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