필터 지우기
필터 지우기

Dividing matrix in four parts

조회 수: 1 (최근 30일)
Maryam Hamrahi
Maryam Hamrahi 2016년 6월 27일
댓글: Maryam Hamrahi 2016년 6월 27일
I have a matrix with three columns and n rows.
I would like to produce four matrices with three columns and different rows. it is not important that matrices do not have the same rows.
For instance:
A has 210 rows.
I want to have B with 40 rows, C with 60 rows, D with 30 rows, and E with 80 rows.
Thanks a lot for help.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 27일
A=rand(210,3);
out=mat2cell(A,[40 60 30 80]',3)
You have your 4 matrices
out{1}
out{2}
out{3}
out{4}
  댓글 수: 1
Maryam Hamrahi
Maryam Hamrahi 2016년 6월 27일
many thank for the response. I want to have a code which work with different A

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


Jan Orwat
Jan Orwat 2016년 6월 27일
편집: Jan Orwat 2016년 6월 27일
A = zeros(210,3); %example
split = [40 60 30 80];
A_split = mat2cell(A,split);
[B, C, D, E] = A_split{:};
doc mat2cell
  댓글 수: 1
Maryam Hamrahi
Maryam Hamrahi 2016년 6월 27일
Many thanks for the response. But A was just an example.
I want a code to work for every matrix with n rows and three columns.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by