필터 지우기
필터 지우기

Splitting column to different length columns in matrix

조회 수: 2 (최근 30일)
Hüsamettin Taysi
Hüsamettin Taysi 2018년 12월 14일
편집: Omer Yasin Birey 2018년 12월 14일
Hello, for example with the function below, I know that it is possbile split a column to same length columns. If we have 70 values, after this process we get 7x10 matrices.
a=reshape(a,10,[])
But my aim is for example, we have 30 values and I want to split them like;
  1. column 2.column 3.column
5 values 12 values 13 values
Is it possible?
Thanks in advance.

답변 (1개)

Omer Yasin Birey
Omer Yasin Birey 2018년 12월 14일
편집: Omer Yasin Birey 2018년 12월 14일
It is not possible in numerical array. However, you may do it with cell arrays by using mat2cell as Stephen mentioned in the comment section.
But it will look like this
C =
1 2
1) [1;2;3;4] [1;2;3;4;5]
Instead of this
  1. column 2.column 3.column
5 values 12 values 13 values
You can use array indexing if you don't mind zeros
a = zeros(13,3);
a(1:5,1) = randi(5,1);
a(1:12,2) = randi(5,1);
a(1:13,3) = randi(5,1);
And then maybe you can ignore the zeros somehow.
Or, better you can use cell arrays instead of double
a = cell(13,3);
a(1:5,1) = {1};
a(1:12,2) = {1};
a(1:13,3) = {1};
So you know there is no data stored in empty cells.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by