Have any command for copy variable without loop.

A=[1; 2; 3];
B=[4, 5, 6];
for k = 1:20
c(:,:,k) = A;
d(:,:,k) = B;
end
I want to calculate values of c(:,:,k) and d(:,:,k) without loop.

 采纳的回答

Ranjan - try using repmat to repeat the copies of your arrays. Your above code should then reduce to
C = repmat(A,1,1,20);
D = repmat(B,1,1,20);

更多回答(0 个)

类别

帮助中心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!

Translated by