Splitting data array into sub arrays
16 次查看(过去 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 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!