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

Thorsten
Thorsten 2016년 6월 21일
It would be helpful to upload your data, or at least a minimal version that reproduces the errors you describe below.
Stephen23
Stephen23 2016년 6월 21일
편집: Stephen23 2016년 6월 21일
@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.

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

 채택된 답변

Star Strider
Star Strider 2016년 6월 16일
편집: Star Strider 2016년 6월 16일

0 개 추천

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

Tessa Aus
Tessa Aus 2016년 6월 17일
When putting this in my code I am receiving the error: Error using sum; Too many input arguments.
Star Strider
Star Strider 2016년 6월 17일
My code in both the initial and edited code (edited to accommodate the cell vector) runs without error in R2016a.
I cannot reproduce the error you’re getting.
I don’t know the reason it doesn’t work with your code because I don’t have your code.
Tessa Aus
Tessa Aus 2016년 6월 17일
What does 'Uni' mean maybe my lack of understanding of that is what is causing the error. And yes I am using a cell array with numbers and letters.
Star Strider
Star Strider 2016년 6월 17일
The ‘'Uni',0’ is shorthand for ‘'UniformOutput',false’.
From the documentation for cellfun, that option:
  • Requests that the cellfun function combine the outputs into cell arrays A1,...,Am. The outputs of function func can be of any size or type.
I’m not sure how to advise you with respect to processing your ‘cell array with numbers and letters’. This is new information that I would have preferred you’d mentioned at the outset, preferably with some sample data and how you want to handle the numbers and letters.
Tessa Aus
Tessa Aus 2016년 6월 21일
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 2016년 6월 21일
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.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 16일

0 개 추천

idx=a(:,1)>-150 & a(:,1)<0
out=sum(~idx)

댓글 수: 1

Tessa Aus
Tessa Aus 2016년 6월 16일
I get an error "Undefined operator '>' for input arguments of type 'cell'. This is the error I keep getting whenever I use this signage.

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

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2016년 6월 16일

편집:

2016년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by