# Length of the structure array

조회 수: 27(최근 30일)
SS 2020년 6월 9일
댓글: SS 2020년 6월 10일
Hi. I am working with a structure array S (1 X 20,000) with 3 fields. I want to count the number of S(i) that meet a condition on one of its fields. For example,
Here is the input,
S(1).f1=[11,17,3,18,15,13], S(1).f2=[100,20,50,60,70,140] and S(1).f3=[-10,20,-50,42,-70,140] ;
S(2).f1=[10,12,14,17,19], S(2).f2=[101,54,69,20,11] and S(2).f3=[17,-54,69,-20,37];
S(3).f1=S(1).f1=[19,17,13,14,15,10,11,16], S(3).f2=..... and S(3).f3=...........;
S(4).f1=[11,17,30,108,15,13,37,14], , S(4).f2=..... and S(4).f3=............;
.
.
S(i).f1=...., S(i).f2=.... and S(i).f3=............;
Let's say, I have a condition on f1: 10 < f1 <=20. Based, on this condition I want the count of S(i) whose f1 is strictly in the these limits. In this example, S(2).f1 and S(3).f1 has all the f1 in bewteen 10 and 20, the count is 2.
I want to implement this on S (1 X 20,000). Can someone help me with this?

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

### 채택된 답변

Walter Roberson 2020년 6월 10일
count = nnz(arrayfun(@(S) all(10 < S.f1 & S.f1 <= 20), S))
SS 2020년 6월 10일
Thank you.

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

### 범주

Find more on Structures in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by