The logical indices contain a true value outside of the array bounds

6 ビュー (過去 30 日間)
University
University 2024 年 2 月 16 日
コメント済み: University 2024 年 2 月 16 日
Please, how can I tackle "The logical indices contain a true value outside of the array bounds" error? I don't what exactly is the cause.
load('sol_active_flow_varinying_xiL.mat')
xi=xivals;
L =Lvals;
intabsul = intabsul;
intabsur =intabsur;
absintul =absintul;
absintur =absintur;
%% This is where I having an issue
test1 = intabsul == absintul & intabsur == absintur;
subset_xi_1 = xivals(test1);
The logical indices contain a true value outside of the array bounds.
subset_Lv_1 = Lvals(test1);
test2 = intabsul ~= absintul & intabsur ~= absintur;
subset_xi_2 = xivals(test2);
subset_Lv_2 = Lvals(test2);
%
test3 = intabsul ==absintul & intabsur ~= absintur;
subset_xi_3 = xivals(test3);
subset_Lv_3 = Lvals(test3);
%
test4 = intabsul ~= absintul & intabsur == absintur;
subset_xi_4 = xivals(test4);
subset_Lv_4 = Lvals(test4);
  6 件のコメント
Fangjun Jiang
Fangjun Jiang 2024 年 2 月 16 日
This is the exact same question you asked previously. The cause of the problem has been clearly explained with a simple example. You have your data and you can run your code line by line, observe the value of the variable and see what is not expected and figure out a solution.
Without comments and with those confusing variable names, it's really hard to try to understand what the program tries to achieve. If you want help, you have to explain to an extent that others can understand.
University
University 2024 年 2 月 16 日
Sorry, Fangjun. From the above explanation, deos mean that xivals has to 20 by 20 matrix for it work?? I just want to get the values of xivals and Lvals if this contidition: "intabsul ~= absintul & intabsur ~= absintur" is satisfied My xivals and Lvals is a vecor of length 20 each.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2024 年 2 月 16 日
編集済み: Fangjun Jiang 2024 年 2 月 16 日
test2 = intabsul ~= absintul & intabsur ~= absintur
the resulting "test2" is a 20x20 logical matrix. You can't use it to index a vector of 20 elements.
Do you actually want the index only if the "whole column" or "whole row" of "test2" is all true? If yes, you need to use the all() function, apply it on the column or row.
In this cases, there are three rows of "test2" are all true
test2 = intabsul ~= absintul & intabsur ~= absintur;
index=all(test2,2);
subset_xi_2 = xivals(index)
subset_Lv_2 = Lvals(index)
subset_xi_2 =
111.8421 118.4211 125.0000
subset_Lv_2 =
1.0e-05 *
0.5967 0.6317 0.6667
  1 件のコメント
University
University 2024 年 2 月 16 日
Oh I see, thank you so much for your explanation. I understand how it works now.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by