How to know which values in a cell exceed a threshold
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
John Doe
am 10 Okt. 2017
Kommentiert: John Doe
am 10 Okt. 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 Kommentare
Akzeptierte Antwort
Matthew
am 10 Okt. 2017
Bearbeitet: Matthew
am 10 Okt. 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};
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!