필터 지우기
필터 지우기

Split an Array in sub-arrays based on the first number in the column

조회 수: 3 (최근 30일)
Hello,
I have an array M 2939x4 that I would like to split in sub-arrays based on the number in the first column.
I mean in the first colunm a number is listed, first 0, then 0.02, then 0.04 and so on (with an increment of 0.02) until 2.2, the problem is that the times that this number appear is not always the same (for example the 0 is on the first 28 rows, the 0.02 in the following 24 and the 0.04 in the next 29).
My idea was to find the number of different number listed in the first column (time) and how many times they occurs (b).
[time,b] = unique(M(:,1));
b = [b; length(M)];
How can I continue it?
Thanks in advance.

채택된 답변

Stephen23
Stephen23 2022년 4월 19일
M = [[0;0.2;0.2;0.4;0.6;0.6;0.6],rand(7,3)]
M = 7×4
0 0.4950 0.3418 0.1799 0.2000 0.7419 0.8047 0.6176 0.2000 0.0316 0.7905 0.7259 0.4000 0.0520 0.9471 0.8603 0.6000 0.2431 0.9200 0.8624 0.6000 0.2946 0.9786 0.6720 0.6000 0.1605 0.0039 0.7209
D = diff(find([1;diff(M(:,1));1]));
C = mat2cell(M,D,4)
C = 4×1 cell array
{[ 0 0.4950 0.3418 0.1799]} {2×4 double } {[0.4000 0.0520 0.9471 0.8603]} {3×4 double }
C{:}
ans = 1×4
0 0.4950 0.3418 0.1799
ans = 2×4
0.2000 0.7419 0.8047 0.6176 0.2000 0.0316 0.7905 0.7259
ans = 1×4
0.4000 0.0520 0.9471 0.8603
ans = 3×4
0.6000 0.2431 0.9200 0.8624 0.6000 0.2946 0.9786 0.6720 0.6000 0.1605 0.0039 0.7209
  댓글 수: 3
Fabio Taccaliti
Fabio Taccaliti 2022년 4월 19일
편집: Fabio Taccaliti 2022년 4월 19일
What about if I want to plot each last 3 columns of the sub-arrays? column 2 is the x-cooediante, column 3 the y and column 4 the z.
figure(1)
for i = length(C)
hold on; grid on; grid minor; axis equal;
scatter3(C{i}(:,2),C{i}(:,3),C{i}(:,4))
view(3)
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
end
Something like this, but this plot just the first one

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by