How to return corresponding entries of an array using if statement

1 回表示 (過去 30 日間)
University
University 2024 年 2 月 12 日
コメント済み: University 2024 年 2 月 14 日
Please how can I handle this:
I want to use if statement such that
if intabsul == absintul && intabsur==absintur
returns the corresponding entries of the xivals and Lvals
elseif intabsul ~= absintul && intabsur~= absintur
return the corresponding entries of the xivals and Lvals
elseif intabsul == absintul && intabsur~=absintur
return the corresponding entries of the xivals and Lvals
elseif intabsul ~= absintul && intabsur==absintur
return the corresponding entries of the xivals and Lvals
else do nothing.
See my code below, although is not complete:
xivals = linspace(0, 10, 10);
Lvals = linspace(2e-8, 666.7e-6, 5);
for il=1:length(Lvals);
for ixi=1:length(xivals)
%
intul(ixi, il) = trapz(yvals, uxl(:, ixi, il));
intabsul(ixi, il) = trapz(yvals, abs(uxl(:, ixi, il)));
%
intur(ixi, il) = trapz(yvals, uxr(:, ixi, il));
intabsur(ixi,il) = trapz(yvals, abs(uxr(:, ixi, il)));
%
absintul(ixi, il) = abs(trapz(yvals, uxl(:, ixi, il)));
%
absintur(ixi,il) = abs(trapz(yvals, uxr(:, ixi, il)));
end
end

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 2 月 12 日
mask = intabsul == absintul & intabsur==absintur;
subset_xi_1 = xivals(mask);
subset_Lv_1 = Lvals(mask);
mask = intabsul ~= absintul & intabsur~= absintur;
subset_xi_2 = xivals(mask);
subset_Lv_2 = Lvals(mask);
and so on.
  2 件のコメント
University
University 2024 年 2 月 12 日
編集済み: University 2024 年 2 月 12 日
Thank you so much for your help. I tried it but I received:
Error in active_flow_run (line 242)
subset_xi_1 = xivals(mask);
"The logical indices contain a true value outside of the array bounds".
Another thing is that fact : intabsul == absintul & intabsur==absintur might not be necessarily true for every entries of the matrices.
I thought of something like: intabsul-absintul < epsilon
where epsilon= 10^-11. If want to use this approach, i.e.,
if intabsul-absintul<epsilon & intabsur-absintur<epsilon
return the corresponding values of xivals and lvals
and so...
How do I handle this case?
University
University 2024 年 2 月 14 日
Hi Walter,
Please how can handle this error?
Error in active_flow_run (line 242)
subset_xi_1 = xivals(mask);
"The logical indices contain a true value outside of the array bounds".
I have tried several ways but I still receive this error.

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

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by