using while in combining two vectors

4 visualizaciones (últimos 30 días)
ABDEL EL GH
ABDEL EL GH el 16 de Mayo de 2022
Respondida: Voss el 16 de Mayo de 2022
Hello, Please help me with the following: Consider two vectors, A=[a1;a2;a3] and B=[b1;b2;b3]. How can I get a new vector C using while, where C=[a1;b1;a2;b2;a3;b3] ? Thank you.

Respuestas (1)

Voss
Voss el 16 de Mayo de 2022
A = [1;2;3];
B = [4;5;6];
n = numel(A);
C = zeros(2*n,1);
i = 1;
while i <= n
C(2*i-1) = A(i);
C(2*i) = B(i);
i = i+1;
end
disp(C);
1 4 2 5 3 6

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by