Splitting data array into sub arrays

15 visualizzazioni (ultimi 30 giorni)
Ozgur
Ozgur il 14 Set 2011
Commentato: Saurabh Bedi il 5 Dic 2020
Hi everyone,
I have a acquired data of 10 sec with 30720 Hz sampling freq, which results 307200 data points.
I want to split this data array into 10 sub arrays and process it seperately and use it after.
I can do it step by step using classical array manipulations but I have 8 of these data sets and splitting those causes 80 steps to manage it.
Is it possible to do that with a for or a while loop at one action? I didn't think of a algorithm about that yet. Any suggestions would be helpful.
Regards,
OZGUR

Risposta accettata

Jan
Jan il 14 Set 2011
The creationm of sub-arrays is inefficient. It would be better to use a 2D array:
x = rand(1, 307200);
y = reshape(x, 30720, 10);
Then the i.th part is y(:, i), which is fast and simple.
If you really want to get different arrays, use a cell:
C = num2cell(reshape(x, 30720, 10), 1);
Then C{1}, C{2}, ... are your vectors.
Do not create different variables C1, C2, ... !
  3 Commenti
Nimrod
Nimrod il 15 Set 2016
Hey Jan but what if your x size is not even
Saurabh Bedi
Saurabh Bedi il 5 Dic 2020
Hey Jan,
I have a similar issue where I am trying to reshape an array in order to form sub-arrays for a very large array. Is there a way to reshape an array containing non-integer values? For example:- i have a large array of approx. 200,000 points with values like -124.3569. How can I reshape this array?
Actually I want to split this array into sub-arrays Or cells.
I used the following code to reshape and split:-
time_avg_len = [1, 10, 30];
for i = time_avg_len(1,1:end)
if i == time_avg_len(1,3)
number_bins = ceil(max(tau/i));
disp(number_bins)
s = length(angle_array_hr);
disp(s)
angle_array_hr_reshape = reshape(angle_array_hr, (s/number_bins), number_bins);
%C = num2cell(angle_array_hr_reshape,1);
%disp(error_signal_split_list)
end
end
Surprisingly, If I choose i==30, the code works and I am able to reshape and split the array into 2 sub-arrays OR cells. But If I choose i==10 OR 1, It gives an error: "Error using reshape. Size arguments must be real integers." Please let me know why this happens. Is it because my array has non-integer values? but then it should not work for i==30 as well.
Anyone, Kindly help me with this.
Thanks in advance.

Accedi per commentare.

Più risposte (2)

Ozgur
Ozgur il 17 Set 2011
Another question, if I want to put the subarrays into cell manually, how can I do that? (By not using "cell" function)
I've tried several for loop actions, but I couldn't manage it.
OZGUR

Gokturk
Gokturk il 18 Dic 2012
Hi, I want to add a question related to this. How can we split data into sub arrays based on dates? Lets say we do have thousands data points for diff dates totaling a million rows in xls. I want to split this data into arrays based on the dates as the number of observations is changing from date to date. Many thnks for the help

Community Treasure Hunt

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

Start Hunting!

Translated by