what does data_gt(:,7) == 1, :) do in Matlab?
1 view (last 30 days)
Show older comments
Tianyu Cheng
on 27 Nov 2020
Commented: Tianyu Cheng
on 27 Nov 2020
data_gt = data_gt(data_gt(:,7) == 1, :);
what does data_gt(:,7) == 1, : do?
0 Comments
Accepted Answer
Walter Roberson
on 27 Nov 2020
data_gt(:,7) == 1
extracts column 7 from all rows of matrix data_gt . It then compares each of the values to the constant one, returning a logical vector with the same number of entries as there are rows in data_gt . Each entry will be logical value false or true
data_gt(data_gt(:,7) == 1, :)
takes that logical vector as input into a data_gt(INDEX, :) operation . Each entry in the vector that is true results in the corresponding entire row being selected for output, and each entry in the vector that is false results in the corresponding entire row not being selected for output. Therefore data_gt(data_gt(:,7) == 1, :) ends up outputing the rows of data_gt in which column 7 equals 1.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!