필터 지우기
필터 지우기

Splitting data array into sub arrays

조회 수: 46 (최근 30일)
Ozgur
Ozgur 2011년 9월 14일
댓글: Saurabh Bedi 2020년 12월 5일
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

채택된 답변

Jan
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
Nimrod
Nimrod 2016년 9월 15일
Hey Jan but what if your x size is not even
Saurabh Bedi
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개)

Ozgur
Ozgur 2011년 9월 17일
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 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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by