Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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 commentaire
Stephen23
Stephen23 le 31 Août 2016
Modifié(e) : Stephen23 le 31 Août 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.

Connectez-vous pour commenter.

Réponses (1)

Thorsten
Thorsten le 31 Août 2016
Modifié(e) : Thorsten le 31 Août 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)))

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by