How do I add ones after each element in a vector?

I need to add an element containing 1 after each element in a vector. I was using the following code for months but after the update to 2020b it stopped working.
xdata = [123; 234; 345; 456; 567; 678];
withones = [xdata; ones(size(xdata))];
withones = withones(:)';
It used to give me this, which is what I want:
[123 1 234 1 345 1 456 1 567 1 678 1]
But now it gives me this:
[123 234 345 456 567 678 1 1 1 1 1 1]
I do not want to do this manually.

Answers (1)

KSSV
KSSV on 20 Nov 2020
Edited: KSSV on 20 Nov 2020
You are appending the one's at the end, so according to your code the output given is correct. To get what you want follow:
xdata = [123; 234; 345; 456; 567; 678];
withones = ones(2*length(xdata),1) ;
withones(1:2:end) = xdata

Categories

Asked:

on 20 Nov 2020

Edited:

on 20 Nov 2020

Community Treasure Hunt

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

Start Hunting!