필터 지우기
필터 지우기

How to apply a relational operator on a cell in MATLAB?

조회 수: 5 (최근 30일)
Haitham AL Satai
Haitham AL Satai 2022년 9월 20일
댓글: Haitham AL Satai 2022년 9월 20일
I would like to know the number of values that are less than 0.0038 in a cell of 41 X 41 double.
For example, I have the cell below:
B = num2cell(rand(41));
When I applied such condition
sum(A(:) < 0.0038)
, it gave me an error, which is Operator '<' is not supported for operands of type 'cell'.
So, do I need to convert the cell to a matrix and apply the operation? Or is there any specific way to use this condition on the cell directly?
  댓글 수: 2
Stephen23
Stephen23 2022년 9월 20일
B = num2cell(rand(41));
Why use such an inefficient approach to storing numeric data?
Most likely your task would be much simpler if you used a numeric array.
Star Strider
Star Strider 2022년 9월 20일
Or is there any specific way to use this condition on the cell directly?
Yes.

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

채택된 답변

Star Strider
Star Strider 2022년 9월 20일
Use the cellfun and nnz functions —
B = num2cell(rand(41));
A = nnz(cellfun(@(x)x<0.0038, B))
A = 5
.
  댓글 수: 4
Star Strider
Star Strider 2022년 9월 20일
@Haitham AL Satai — My pleasure!
@Stephen23 — Thank you!
Haitham AL Satai
Haitham AL Satai 2022년 9월 20일
@Stephen23 Thank you for your notice. I got it now. Thank you again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by