Help with Table and Row indexing

3 次查看(过去 30 天)
Hi,
I have the following table Predictions, where there are 2 Days, 2 different Time points, for 2 different Birds, 3 Tries per day.
I want to:
  1. Check If the Row number is a True Positive (meaning the column True and Predicted have the same value)
  2. Check If the Row number is a True Positive and the Predicted value is '1'. Save those Row numbers in a variable called RN.
  3. From another table T with the same dimentions as the Predictions table, I only want to keep the Row numbers as assigned to RN.
Can you help?

采纳的回答

Voss
Voss 2022-5-14
编辑:Voss 2022-5-14
S = load('predictions.mat');
Predictions = S.Predictions
Predictions = 22×6 table
Day Bird Time Try True Predicted ___ ____ ____ ___ ____ _________ 1 004 Pre 1 0 0 1 004 Pre 2 0 0 1 004 Pre 3 0 0 1 004 Post 1 0 0 1 004 Post 2 0 0 1 004 Post 3 0 0 1 006 Pre 1 1 1 1 006 Pre 2 1 1 1 006 Pre 3 1 1 1 006 Post 1 1 1 1 006 Post 2 1 1 2 004 Pre 1 0 0 2 004 Pre 2 0 0 2 004 Pre 3 1 0 2 004 Post 1 0 0 2 004 Post 2 0 0
isTruePositive = Predictions{:,'True'} == Predictions{:,'Predicted'};
isTruePositivePredicted1 = isTruePositive & Predictions{:,'Predicted'} == 1;
% here are the row numbers:
RN = find(isTruePositivePredicted1)
RN = 8×1
7 8 9 10 11 18 19 21
% Two different ways to keep only certain rows
% of the other table T:
% Option 1: use logical indexing, and discard
% rows of T that are not true positive where
% 1 was predicted (in this case you don't need RN):
T{~isTruePositivePredicted1,:} = [];
% Option 2: use row indices RN to keep those rows
% that are true positive where 1 was predicted:
T = T{RN,:};

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by