Merge two columns into one column?

3 views (last 30 days)
pkh
pkh on 1 Dec 2015
Commented: pkh on 1 Dec 2015
I have two columns that i want to merge into one column. Meaning i want
A=[123; 321] and
B=[456; 654] to be merged/combined into a new column
C=[123456; 321654]
I this possible?

Accepted Answer

Thorsten
Thorsten on 1 Dec 2015
C = 10.^ceil(log10(B)).*A + B;
  5 Comments
Thorsten
Thorsten on 1 Dec 2015
Edited: Thorsten on 1 Dec 2015
You can use
format bank
to change the way the numbers are shown in the command window. Note that this doesn't affect your algorithms. unique will give the same results, regardless of how the numbers are actually displayed.
pkh
pkh on 1 Dec 2015
Yes it works as intended with unique, thank you

Sign in to comment.

More Answers (1)

Stephen23
Stephen23 on 1 Dec 2015
Edited: Stephen23 on 1 Dec 2015
>> A = [123,321,20001130];
>> B = [456,654,32378];
>> F = @(n)arrayfun(@int2str,n,'UniformOutput',false);
>> cellfun(@(a,b)str2double([a,b]),F(A),F(B))
ans =
123456 321654 2000113032378

Community Treasure Hunt

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

Start Hunting!