how to clip column into vectors with the rules I set

조회 수: 1 (최근 30일)
ZHEN XU
ZHEN XU 2020년 9월 18일
편집: Stephen23 2020년 9월 24일
I wanna clip the 2nd column while the first cloumn increased by 10 each time. Note: the output vector length of 2nd column between 10 and 20 could be different. For example, the matrix
A =
1.0000 0.3000
5.2000 0.8000
9.2000 95.0000
17.8500 21.0000
19.5600 78.0000
20.5800 9.2300
25.0000 8.0000
28.0000 9.6500
29.1200 45.0000
Output:
B1 =
0.3000
0.8000
95.0000
B2 =
21
78
B3 =
8.0000
9.6500
45.0000
How should I do this? Thank you.

답변 (1개)

Stephen23
Stephen23 2020년 9월 24일
편집: Stephen23 2020년 9월 24일
>> [~,~,idx] = unique(floor(A(:,1)/10));
>> out = accumarray(idx,A(:,2),[],@(v){v});
>> out{1}
ans =
0.3000
0.8000
95.0000
>> out{2}
ans =
21.0000
78.0000
>> out{3}
ans =
9.2300
8.0000
9.6500
45.0000

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by