Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 31 Aug. 2016
Bearbeitet: Stephen23 am 31 Aug. 2016
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Thorsten
Thorsten am 31 Aug. 2016
Bearbeitet: Thorsten am 31 Aug. 2016
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)))

Kategorien

Mehr zu Data Import and Export 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!

Translated by