Finding arrays above threshold value

조회 수: 4 (최근 30일)
Manny Kins
Manny Kins 2019년 4월 16일
댓글: Manny Kins 2019년 4월 17일
I have a struct AT.AX
AX has the following values:
1x370 double
1x1007 double
1x3957 double
1x6309 double
1x1648 double
1x2032 double
1x1173 double
1x16837 double
1x15977 double
1x267 double
Is there a way to find all the elements with length greater than 2000 and assign them to a new variable?
Thanks
  댓글 수: 2
Stephen23
Stephen23 2019년 4월 16일
"I have a struct AT.AX"
"Is there a way to find all the cells ..."
Structure arrays do not have cells (but they do have elements).
Please clarify if you have a structure array or a cell array.
Manny Kins
Manny Kins 2019년 4월 17일
Hi, I used the word cell quite carelessly, I had a structure array with elements. I have edited my question so it becomes a bit clearer to anyone else reading. Thanks again for your help.

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

채택된 답변

Stephen23
Stephen23 2019년 4월 16일
Fake data:
AT(1).AX = rand(1,370);
AT(2).AX = rand(1,1007);
AT(3).AX = rand(1,3957);
AT(4).AX = rand(1,6309);
AT(5).AX = rand(1,1648);
AT(6).AX = rand(1,2032);
AT(7).AX = rand(1,1173);
AT(8).AX = rand(1,16837);
AT(9).AX = rand(1,15977);
AT(10).AX = rand(1,267);
And then simply:
L = cellfun('length',{AT.AX});
Z = AT(L>2000)
  댓글 수: 1
Manny Kins
Manny Kins 2019년 4월 16일
Thank you for your help, KSSV also came up with a similar solution but this one is more directly applicable to my setup.

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

추가 답변 (1개)

KSSV
KSSV 2019년 4월 16일
% Make some random data for demo
A = cell(10,1) ;
for i = 1:10
N = randperm(1000,1) ;
A{i} = rand(N,1) ;
end
% Pick cells whose length greater than 500
L = cellfun(@length,A) ;
B = A(L>500)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by