how to load values of two matrices into one matrix?
1 view (last 30 days)
Show older comments
kavya kolipakula
on 25 Feb 2019
Commented: kavya kolipakula
on 25 Feb 2019
let A=[1;2;3;4;5]
B=[6;7;8;9;10]
and I want h=[1;6;2;7;3;8;4;9;5;10]
0 Comments
Accepted Answer
Alex Mcaulley
on 25 Feb 2019
tmp = 1:length(A)+length(B);
h = zeros(length(A)+length(B),1)
h(mod(tmp,2)==1) = A
h(mod(tmp,2)==0) = B
More Answers (2)
Arthur Nascimento
on 25 Feb 2019
A=[1;2;3;4;5]
B=[6;7;8;9;10]
for i=1:length(A)*2
if mod(i,2)==0
h(i)=B(ceil(i/2))
else
h(i)=A(ceil(i/2))
end
end
Jos (10584)
on 25 Feb 2019
Many roads to Rome, which all learn you about using transpose, reshape, concatention, and/or clever indexing
H1 = reshape([A B].', [], 1) % when A and B have the same lengths
H2([1:2:2*numel(A) 2:2:2*numel(B)+1], 1) = [A ; B]
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!