필터 지우기
필터 지우기

How can I compare an input value to coefficients in a cell array?

조회 수: 5 (최근 30일)
Adam
Adam 2013년 7월 16일
Hello all,
I am probably trying to do the easiest thing ever, but I'm unsure of how to do it. I have a list of coefficients in a cell array and I want to find out if any of those coefficients are greater than the value which I put in. If any values are larger I want to be able to see the position (number of the coefficient) as well as the value of the coefficient itself. Any help would be much appreciated.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 16일
편집: Azzi Abdelmalek 2013년 7월 16일
a={10 30 50 0 20 60 70 80};
idx=find(cellfun(@(x) x>20,a))
values=a(idx)
%or
idx=find(cell2mat(a)>20)
values=a(idx)

David (degtusmc)
David (degtusmc) 2013년 7월 16일
편집: David (degtusmc) 2013년 7월 31일
As it was suggested, convert the content of the cell to a matrix (cell2mat) and then perform comparisons. You could also convert from matrix to string (mat2str) and then use something like strcmp to make the comparison. Below are the links to the function documentation. I hope this helps.
  댓글 수: 2
Adam
Adam 2013년 7월 17일
Thanks! This helped a great deal. Is it possible to obtain the index value next to the actual coefficient value? I basically need to see the position of each coefficient.
David (degtusmc)
David (degtusmc) 2013년 7월 18일
There is a couple of ways you could do this. Two that I can think of, is using a function such as cellfun (as mentioned above) or a loop to find an extract what you are looking for.
I found a question that is very similar to what you are trying to accomplish. Take a look at it and see if it helps. The link is below:
This other forum may also have useful things as well...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by