필터 지우기
필터 지우기

How to know which values in a cell exceed a threshold

조회 수: 1 (최근 30일)
John Doe
John Doe 2017년 10월 10일
댓글: John Doe 2017년 10월 10일
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,

채택된 답변

Matthew
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by