Checking Cell Array for positive numbers
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tessa Aus
am 16 Jun. 2016
Bearbeitet: Stephen23
am 21 Jun. 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 Kommentare
Thorsten
am 21 Jun. 2016
It would be helpful to upload your data, or at least a minimal version that reproduces the errors you describe below.
Akzeptierte Antwort
Star Strider
am 16 Jun. 2016
Bearbeitet: Star Strider
am 16 Jun. 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 Kommentare
Star Strider
am 21 Jun. 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.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations 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!