I have a matrix 20X1. I want to read all the elements of c2 and put the condition as if element of c2 is greater that zero and less than 70 then display that element else return. how should I do?

조회 수: 2 (최근 30일)
c2 =
[ 1.3589]
[ 7.9773]
[28.2728]
[28.2728]
[ 0.8705]
[ 7.4681]
[28.2728]
[37.0303]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
[ 0]
  댓글 수: 1
Stephen23
Stephen23 2016년 8월 31일
편집: Stephen23 2016년 8월 31일
Duplicate:
@Sachin Patil: actually it makes it harder for us to help you when you ask the same question in multiple locations. Then we cannot keep track of your information and explanations, and also what answers you have been given.

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

답변 (1개)

Thorsten
Thorsten 2016년 8월 31일
편집: Thorsten 2016년 8월 31일
for i = 1:numel(ca)
if ca{i} > 0 & ca{i} < 70
% do this
else
% do that
end
end
If you just want to extract the elements that fulfil the condition:
First remove the empty elements:
ca2 = ca(~cellfun(@isempty, ca))
Next use logical indexing to pick the elements from ca2:
cell2mat(ca2(cellfun(@(c) 0 < c & c < 70 , ca2)))

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by