How to split data into multiple "chunks"?

Is there an algorithm to split a dataset of a few thousand points into multiple "chunks" of length 'n'?

답변 (2개)

KSSV
KSSV 2020년 10월 15일
편집: KSSV 2020년 10월 15일

1 개 추천

Read about reshape.
A = rand(1,1000) ;
n = 100 ;
iwant = reshape(A,100,[]) ;
size(iwant)
iwant(:,1) % 10 columns of 100 rows

댓글 수: 1

Xuan Gip
Xuan Gip 2023년 6월 27일
is there any way to reshape based on a pattern? For example, I have a data that goes 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 and I want the reshape the entire data set to start from that first "1" to the last "1" on the second group of 1s.

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

Ameer Hamza
Ameer Hamza 2020년 10월 15일

1 개 추천

Another approach is to create a cell array.
M = rand(1, 1000);
n = 100;
C = mat2cell(M, 1, n*ones(numel(M)/n, 1))

댓글 수: 3

I get the following error:
This is probably due to 'M' not being an integer when divided by 'n'. What is the best way to fix this?
Error using ones
Size inputs must be integers.
Ameer Hamza
Ameer Hamza 2020년 10월 16일
Your number of elements in vector M must be a multiple of 'n'. If it is something else, you will get that error.
KSSV
KSSV 2020년 10월 16일
  1. Try to make M divisble by n, by appending NaN's to your array.
  2. Or make first few chunks of same size and leave last chunk with reduced elements

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

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2020년 10월 15일

댓글:

2023년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by