How do I rewrite this code to output the same answer without the for loops
1 次查看(过去 30 天)
显示 更早的评论
A = [1 3 5 7 9];
B = [2 4 6 8 10];
L = min([length(A) length(B)]);
C = zeros(1, 2*L);
for i=1:L
C(2*(i-1)+1) = A(i);
C(2*i) = B(i);
end
disp('C = ');
disp(C);
I need the same output accomplished without the presence of a for loop i.e. a vector in the form of [a1 b1 a2 b2 a3 b3]. Thanks for the help.
0 个评论
采纳的回答
rumin diao
2022-9-2
it seems you can delete the for loop and make i a vector:
A = [1 3 5 7 9];
B = [2 4 6 8 10];
L = min([length(A) length(B)]);
C = zeros(1, 2*L);
% for i=1:L
% C(2*(i-1)+1) = A(i);
% C(2*i) = B(i);
% end
i=1:L;
C(2*(i-1)+1) = A(i);
C(2*i) = B(i);
disp('C = ');
disp(C);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!