# How to know which values in a cell exceed a threshold

1 view (last 30 days)
John Doe on 10 Oct 2017
Commented: John Doe on 10 Oct 2017
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 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

Matthew on 10 Oct 2017
Edited: Matthew on 10 Oct 2017
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};
##### 1 CommentShow -1 older commentsHide -1 older comments
John Doe on 10 Oct 2017
This works^^ thank you!

Sign in to comment.

### Categories

Find more on Logical 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!