Filter löschen
Filter löschen

How can i divide data into equal parts?

29 Ansichten (letzte 30 Tage)
shubham shubham
shubham shubham am 24 Nov. 2020
Kommentiert: shubham shubham am 25 Nov. 2020
Suppose we have data from 1:1:100.... I want to divide it such that one variable have data r1=1:1:25 another r2= 26:1:50, r3= 51:1:75 and r4= 76:1:100 .... How can i do this dynamically so I can access r1 in first iteration of loop r2 in second and so on..?

Akzeptierte Antwort

Stephen23
Stephen23 am 24 Nov. 2020
V = 1:100;
C = mat2cell(V,1,[25,25,25,25]);
C{1} % C{2}, etc.
ans = 1×25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  5 Kommentare
Stephen23
Stephen23 am 25 Nov. 2020
Bearbeitet: Stephen23 am 25 Nov. 2020
V = 1:100; % data
B = 4; % required number of blocks
N = numel(V);
X = N*ones(1,B)/B
X = 1×4
25 25 25 25
Of course if N is not exactly divisible by B then you will need to decide on how to split the data into differently-sized blocks, possibly using linspace or rounding or similar.
shubham shubham
shubham shubham am 25 Nov. 2020
thanks soo much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by