Reorder vector without for loop

3 ビュー (過去 30 日間)
Science Machine
Science Machine 2022 年 10 月 3 日
編集済み: Chunru 2022 年 10 月 3 日
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 件)

Chunru
Chunru 2022 年 10 月 3 日
編集済み: Chunru 2022 年 10 月 3 日
A = randn(583200, 10);
B =reshape(A, 540, [], 10);
B = permute(B, [2 1 3]);
B = reshape(B, 583200, 10);
whos
Name Size Bytes Class Attributes A 583200x10 46656000 double B 583200x10 46656000 double cmdout 1x33 66 char
% To verify the results
A(1:540:end, 1) % every 540th points
ans = 1080×1
0.3265 -0.1556 1.3238 -0.5684 -0.7725 -1.6892 1.3998 -1.0533 1.1349 2.0951
B(1:10, 1) % 1st 10 points
ans = 10×1
0.3265 -0.1556 1.3238 -0.5684 -0.7725 -1.6892 1.3998 -1.0533 1.1349 2.0951
  4 件のコメント
Science Machine
Science Machine 2022 年 10 月 3 日
you made A = randn(583200, 1); but its A = randn(583200, 1000); In that case A and B don't have the same dimension
Chunru
Chunru 2022 年 10 月 3 日
編集済み: Chunru 2022 年 10 月 3 日
OK. Now A & B are of the size you specified. (use a smaller value for 2nd dimension)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by