Merge two columns of same table into one

25 vues (au cours des 30 derniers jours)
Adnan Habib
Adnan Habib le 13 Avr 2020
Commenté : Adnan Habib le 13 Avr 2020
Hi,
I have a table with 3 columns like the following:
A B C
'4618' '1193' 3
'9810' '1224' 1
'7810' '27845' 1
'6324' '1627' 6
'8954' '1678' 1
'9629' '2061' 1
I have only shown a small portion of the table, actually it is a 3079X3 table. A and B are cells and C is a double. I want the table to look like this:
AB C
'46181193' 3
'98101224' 1
'781027845' 1
'63241627' 6
'89541678' 1
'96292061' 1
I have tried using horzcat but it didn't work. Can someone please help me out with the code?

Réponse acceptée

Akira Agata
Akira Agata le 13 Avr 2020
Assuming columns A and B are cell array of characters, how about the following?
% Sample input table
A = {'123';'234';'345'};
B = {'1111';'2222';'3333'};
C = [1;2;3];
T1 = table(A,B,C);
% Create output table
AB = strcat(T1.A,T1.B);
T2 = table(AB,C);
  1 commentaire
Adnan Habib
Adnan Habib le 13 Avr 2020
This worked nicely! Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by