Splitting 1 column array

Hi all,
I have various column matrices with varying number of elements from 38-202. I want to split each matrix into 5 small matrices each containing the same number of elements. The distribution of numbers into each can be random. If the original matrix has more elements, some can be ignored as well. Like for example if the original matrix has 204 elements and I want to split it into 5 matrices. So only 200 elements can be shuffled and 4 need to be ignored.
Is there any function in MATLAB I can use?
Nancy

 채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 16일

1 개 추천

num_subsets = 5;
matlen = length(YourVector);
num_to_use = matlen - mod( matlen, num_subsets );
idx = randperm(matlen);
shuffled = YourVector(idx(1:num_to_use));
subsets = reshape(shuffled, [], num_subsets);
The subsets would then be the columns.

댓글 수: 3

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 16일
the result is one matrix
Walter Roberson
Walter Roberson 2012년 8월 16일
Yes, but I did indicate that the subsets would be the columns. Splitting into individual matrices is usually not a good idea in this kind of situation.
Nancy
Nancy 2012년 8월 16일
Works perfectly. Thanks Walter :)

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 15일

0 개 추천

example
A=rand(102,2);B=A(1:100,:)
result=reshape(B,5,8,5)

댓글 수: 1

Walter Roberson
Walter Roberson 2012년 8월 16일
Not quite, as that does not do any shuffling.

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

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by