Split a vector into 2 oscillating vectors?
1 view (last 30 days)
Show older comments
I have a .csv file with 1M datapoints, which I've turned into a simple column vector "V". I want to turn it into 2 seperate vectors that take 5k of the data points, back and forth.
So V1 takes 1:5000, 10001:15000, 20,001:25000, etc.
V2 takes 5001:10000, 15001:20000, etc.
Is there an easy way to do this other than typing out 100 sections for each variable?
0 Comments
Accepted Answer
Voss
on 18 Jan 2022
Here is a way to do it. Demonstrating with smaller vectors so as to more easily verify the result. To use it on your column vector V, change N to 1e6 and block_size to 5000.
% N = 1e6;
% block_size = 5000;
N = 140;
block_size = 5;
V = (1:N).'; % some column vector with N elements
idx = (1:block_size).'+2*(0:N/block_size/2-1)*block_size;
V1 = V(idx(:));
V2 = V(idx(:)+block_size);
display([V1 V2]);
0 Comments
More Answers (1)
David Hill
on 18 Jan 2022
v1=zeros(1,500000);
v2=zeros(1,500000);
for k=1:100
v1((k-1)*5000+1:k*5000)=v((2*(k-1))*5000+1:(2*(k-1)+1)*5000);
v2((k-1)*5000+1:k*5000)=v((2*(k-1)+1)*5000+1:k*10000);
end
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!