Select columns from a matrix by treshold value
9 次查看(过去 30 天)
显示 更早的评论
Hi,
i have some data stored in a 7200*600 matrix (600 could also be 300 or 1000 or something in this range). Somewhere in the middle there are some relevant columns (about 20) which contains higher values than the other. I would like to extract these columns for some calculation (row mean only for these columns etc.). So far i do this by:
M = mean(data);
B = (M > min(M)*1.1); % Treshold of 110 %
data_new = B.*data;
data_new(:,all(data_new == 0))=[]; % Removes columns if the entire column is zero
Then i can calculate the mean like:
data_new_mean = mean(data_new(:,3:end),2); % First two columns are suspect data
This works fine so far but i'm looking for a way to get the indices and work with the original matrix instead of building a new one. In the next step i have to extract the data in the following columns (If the relevant columns before were 200, 210, 220... for example, i need 201, 211, 221... in the next step) and that's why the first way isn't convenient anymore. Do you have some ideas?
3 个评论
Walter Roberson
2021-8-30
M = mean(data);
B = (M > min(M, 1)*1.1);
mask = any(M >= B, 1);
mask can now be used as a column index.
采纳的回答
更多回答(1 个)
Matt J
2021-8-30
编辑:Matt J
2021-8-30
find( any(M > min(M)*1.1 ,1) )
2 个评论
Walter Roberson
2021-8-30
That would find the columns that contain only data less than the threshold; the user wanted to find columns that contain at least one datapoint greater than the threshold.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!