Checking Cell Array for positive numbers

12 vues (au cours des 30 derniers jours)
Tessa Aus
Tessa Aus le 16 Juin 2016
Modifié(e) : Stephen23 le 21 Juin 2016
I have a (:,1) array which should be in a range of 0>ArrayValues>-150. What would I use to check to see if any are out of the range, and then list how many are out of the range. I have tried sum(), and Array<0.
  2 commentaires
Thorsten
Thorsten le 21 Juin 2016
It would be helpful to upload your data, or at least a minimal version that reproduces the errors you describe below.
Stephen23
Stephen23 le 21 Juin 2016
Modifié(e) : Stephen23 le 21 Juin 2016
@Tessa Aus: Is there a particular reason why the data in a cell array? This whole task would be trivially easy if the data were stored in a much simpler numeric array.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 16 Juin 2016
Modifié(e) : Star Strider le 16 Juin 2016
Try this:
ArrayValues = randi([-200, 50], 1, 100); % Create Data
OutOfRange = (ArrayValues > -150) & (ArrayValues < 0); % Logical Vector, Use ‘find’ To Get Indices
NrOutOfRange = sum(OutOfRange);
EDIT If ‘ArrayValues’ is a cell array, this works:
ArrayValues = {randi([-200, 50], 1, 100)}; % Create Data
OutOfRange = cellfun(@(x) (x > -150) & (x < 0), ArrayValues, 'Uni',0); % Use ‘cellfun’
NrOutOfRange = sum(OutOfRange{:}); % Change To Address Cell Array
  6 commentaires
Tessa Aus
Tessa Aus le 21 Juin 2016
So I deleted the first cell because it contained the only letters in the cell array. And reran the system and the exact same error showed up. So it looks as though the error is stemming from something other then the letters (which are not gone) and 'uni'. Any final thoughts before I try a different method? The values are for example -112.365 or -105.09. Thanks
Star Strider
Star Strider le 21 Juin 2016
I don’t have either your data or a clear idea of what you want to do, so I have no further thoughts.
You can remove the ‘'Uni',0’ if you want, although I seriously doubt it’s the problem.

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 16 Juin 2016
idx=a(:,1)>-150 & a(:,1)<0
out=sum(~idx)
  1 commentaire
Tessa Aus
Tessa Aus le 16 Juin 2016
I get an error "Undefined operator '>' for input arguments of type 'cell'. This is the error I keep getting whenever I use this signage.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operators and Elementary Operations 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