How to know which values in a cell exceed a threshold
1 回表示 (過去 30 日間)
古いコメントを表示
Dear All,
I have a cell array that contains doubles, it's attached to this question (the help file).
I want to have a new column that contains the values that exceed the threshold. For example, my threshold is 280,
My Data Column
- [24,1464]
- 1464
- 1464
- [24,24]
New Column
- 1464
- 1464
- 1464
- 0
and so on....but they're next to each other
I tried things like : G= gt(Mydata{:},280);as a start to build on but it gave me an error
also: newV={[Mydata{:}]>280} but that gave me logical values and it evaluated my values separately.
If you have any ideas on how I can do this please let me know,
Thank You,
0 件のコメント
採用された回答
Matthew
2017 年 10 月 10 日
編集済み: Matthew
2017 年 10 月 10 日
You can certainly solve this using cellfun.
Assuming you only ever want one value per row, here's a somewhat loose way to use logicals that does what you want. There's probably a more type safe way to do this.
threshold = 280
output = cellfun(@(x) any(x>threshold)*max(x),Data)
An alternative would be to return all the values in cells.
output = cellfun(@(x) x(x>threshold),Data,'UniformOutput',false)
output(cellfun(@(x) isempty(x), output)) = {0};
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!