필터 지우기
필터 지우기

Divide array into 3 parts

조회 수: 17 (최근 30일)
Ahmed Abdulla
Ahmed Abdulla 2022년 1월 15일
답변: Image Analyst 2022년 1월 15일
I have a matrix of size (N,3), where I want to divide this matrix into 3 matrices where matrix 1 is 70% of N, matrix 2 is 15% of N and matrix 3 is 15% of N. is there an easy way to perform this division?

답변 (1개)

Image Analyst
Image Analyst 2022년 1월 15일
Maybe use this
% Create sample data.
N = 100
M = randi(9, N, 3)
% Split matrix up into parts.
[rows, columns] = size(M)
endingRows = round([0.7, 0.85] * rows)
m1 = M(1:endingRows(1), :);
m2 = M(endingRows(1)+1:endingRows(2), :);
m3 = M(endingRows(2) + 1 : end, :);
If you want, you could use randperm to randomize where the rows are taken from.

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by