Splitting data array into sub arrays
조회 수: 17 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Jan
2011년 9월 14일
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
Saurabh Bedi
2020년 12월 5일
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.
추가 답변 (2개)
Gokturk
2012년 12월 18일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!