Can I partition a matrix ito several seperated parts ?

3 views (last 30 days)
can I partition this matrix into 4 parts ?
assume this matrix 29X1, A = [2;2;-3;4;5;6;7;-8;9;-6;5;4;-2;1;3;-9;8;7;4;-5;6;3;2;-1;4;-7;-8;5;-6];
so, I want to group this matrix into 4 seperated groups such as B=7X1, C=7X1, D=7X1, and E=8X1 ?

Accepted Answer

Voss
Voss on 31 Mar 2022
A = [2;2;-3;4;5;6;7;-8;9;-6;5;4;-2;1;3;-9;8;7;4;-5;6;3;2;-1;4;-7;-8;5;-6];
% maybe this:
B = A(1:7);
C = A(8:14);
D = A(15:21);
E = A(22:29);
% or maybe this:
B = A(2:4:end);
C = A(3:4:end);
D = A(4:4:end);
E = A(1:4:end);
% etc., many other partitionings are possible
  4 Comments
omar th
omar th on 1 Apr 2022
actually its not exactly in that order for sure i changed it, but this approach worked in my assumption
thanks again

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 31 Mar 2022
A = [2;2;-3;4;5;6;7;-8;9;-6;5;4;-2;1;3;-9;8;7;4;-5;6;3;2;-1;4;-7;-8;5;-6];
parts = mat2cell(A, [7, 7, 7, 8], 1);
[B, C, D, E] = parts{:};
whos
Name Size Bytes Class Attributes A 29x1 232 double B 7x1 56 double C 7x1 56 double D 7x1 56 double E 8x1 64 double parts 4x1 648 cell
  3 Comments

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!

Translated by