필터 지우기
필터 지우기

Separate values from one column

조회 수: 1 (최근 30일)
Rita Barnabé
Rita Barnabé 2021년 11월 1일
편집: Chunru 2021년 11월 2일
Hi
In this matrix I have 5 groups of values that I want to join.
Here is part of column:
26380
26381
26382
327207
327208
327209
327210
I want that the 3 first numbers to stay in one matrix and the rest in others.
With more cases of this
for n = 1:(length(newData)-1)
if ( newData(n+1,1)) == ( newData(n,1) + 1 )
line0(n+1) = n;
else if ( newData(n+1,1)) ~= ( newData(n,1) + 1 )
line1(n+1) = n+1;
end
end
I tried like this.

채택된 답변

Chunru
Chunru 2021년 11월 2일
편집: Chunru 2021년 11월 2일
x = [26380
26381
26382
327207
327208
327209
327210
400
450
500];
threshold = 1000;
xd = diff(x);
idx = find(abs(xd) > threshold);
idx = [0; idx(:); length(x)];
for i=1:length(idx)-1
y{i} = x(idx(i)+1:idx(i+1));
end
y{1}, y{2}, y{3}
ans = 3×1
26380 26381 26382
ans = 4×1
327207 327208 327209 327210
ans = 3×1
400 450 500

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 11월 2일
편집: Image Analyst 2021년 11월 2일
To group a vector of data into 5 different groups based on their values you can use kmeans() (in the Statistics and Machine Learning Toolbox):
v = [...
26380
26381
26382
327207
327208
327209
327210
222111
222133
222144
222124
111111
111141
111151
121245]
v = 15×1
26380 26381 26382 327207 327208 327209 327210 222111 222133 222144
bar(v);
grid on;
indexes = kmeans(v, 5) % Cluster into 5 groups.
indexes = 15×1
4 4 4 1 1 1 1 3 3 3
indexes is a vector that says what group each of your data values most likely belongs to.

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by