Reorder vector without for loop
显示 更早的评论
I would like to do the following without using the for loop:
for delta=1:540 % get circle points from the line.
vectorB((delta-1)*(1080)+1:(delta)*(1080),:)=vectorA(delta:540:583200,:); % both vecs of size 583200x1000
end % delta
This loop grabs every 540th point in a vector, stores, then increments the amount by 1 and repeats,...,etc.
Is it possible to use a built in function to do the same? Also, I plan to export to C, so whatever function must be supported.
Currently, matlab is more performant than the C coder result.
回答(1 个)
A = randn(583200, 10);
B =reshape(A, 540, [], 10);
B = permute(B, [2 1 3]);
B = reshape(B, 583200, 10);
whos
% To verify the results
A(1:540:end, 1) % every 540th points
B(1:10, 1) % 1st 10 points
4 个评论
Science Machine
2022-10-3
Chunru
2022-10-3
What you want is B. B and A has same dimension as shown above. A small number (not all) of data is shown to verify that the result is correct.
Science Machine
2022-10-3
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!