Selecting all rows if range of column values is greater than 10
조회 수: 7 (최근 30일)
이전 댓글 표시
I am trying to select all rows if a column vaues is greater than 10:
Its like in SQL statemnt Select * From TableA WHERE col1 & col2 & col3.... > 10
Can matlab do the same or do i need a loop if so how do i go by?
Results = TableA(TableA(:,1), (TableA(:, 2:end) > 10))
댓글 수: 0
답변 (1개)
Arjun
2025년 3월 24일
I understand that your goal is to select rows from a table where the values in columns 1, 2, and 3 are all greater than 10.
In MATLAB, you can use logical indexing to focus on columns 1, 2, and 3 for the condition check. By applying the "all" function along the second dimension, you ensure that only rows where all values in these columns are greater than 10 are selected.
You can do so by using the code specified below:
selectedRows = TableA(all(TableA{:, 1:3} > 10, 2), :);
% TableA(:, 1:3) > 10 creates a logical matrix where each element is true if the condition is met.
% all(..., 2) checks if all conditions are true across the specified columns (1 to 3) for each row.
% TableA(..., :) selects all columns of rows where the condition is true.
Kindly refer to the documentation of "all" for better understanding: https://www.mathworks.com/help/releases/R2021a/matlab/ref/all.html
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!