フィルターのクリア

How to use logical indexing for a column of 0 and 1

32 ビュー (過去 30 日間)
iceskating911
iceskating911 2021 年 9 月 28 日
編集済み: iceskating911 2021 年 9 月 29 日
Hello! I am stil learning the basics of matlab and am having trouble with logical indexing. Each excel sheet has the same number of columns yet vary by number of rows. I want to take column "data(:,end-6)" which has a column of 0 and 1 and take all the rows that have the number 1 and create a new array and do more math calculations, using only the rows with a number 1 in that column. Any help would be appreciated. Thank you.

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 9 月 28 日
編集済み: Cris LaPierre 2021 年 9 月 28 日
The best place to get started learning about logical arrays is Ch 12 of MATLAB Onramp.
A simple example:
x = (1:10)';
% extract rows where x>5
ind = x>5
ind = 10×1 logical array
0 0 0 0 0 1 1 1 1 1
x(ind)
ans = 5×1
6 7 8 9 10
% or just simply
x(x>5)
ans = 5×1
6 7 8 9 10
  3 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 9 月 28 日
ind returns a logical for every element, indicating whether it meets the criteria or not. When used as an index, only true values are extracted. The challenge perhaps with your data set is that the extracted data is also 1, so it may be hard to discern between the logical array and the actual values.
Also, if your values are exactly 1, you can use ind = D==1;
iceskating911
iceskating911 2021 年 9 月 28 日
Thank you

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by