Find index of rows in tables with two conditions doesn't work using &&

4 ビュー (過去 30 日間)
Jason
Jason 2024 年 10 月 15 日
コメント済み: Voss 2024 年 10 月 15 日
Hello, I am using a readtable to read a CVS file into a uitable. I like the fact that you can operate on columns using the dot notation with the column heading.
I have seleted the columns of itnerest by using the import options object
opts = detectImportOptions(fullpath) % create importoptions object
opts.SelectedVariableNames = ["YPosNanometer","ZPosNanometer","Tilt"]; % Select which columns to read in
T = readtable(fullpath,opts);
I want to be able to find the row index of any row that has a number 0 in both the 1st or 2nd column, i.e. in both the columns with headings "YPosNanometer","ZPosNanometer".
I thought the below would find these indicies
indx=(find(T.YPosNanometer == 0) && find(T.ZPosNanometer == 0))
But I get the error:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands
to logical scalar values.
So how do I achieve the condition I want?

採用された回答

Voss
Voss 2024 年 10 月 15 日
Use & to operate on non-scalar arrays:
indx = find(T.YPosNanometer == 0 & T.ZPosNanometer == 0)
  2 件のコメント
Jason
Jason 2024 年 10 月 15 日
So easy!!!! thanks
Voss
Voss 2024 年 10 月 15 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by