How to concatenate 4 columns in one table into one coulomb

1 view (last 30 days)
Table 1
imageFilename xmin ymin xmax ymax
________________________________________________________ ____ ____ ____ ____
Japan_001164_jpg.rf.c02ee7802c701e228f23a4033eb236c2.jpg 384 383 415 406
*** Table 2 (result) ***
imageFilename Damage
_______________________________________________________________________________________________ _________________
{'C:\Users\msi-pc\Desktop\Training\New folder (2)\train\Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg'} {[384 383 415 406]}

Answers (2)

Khushboo
Khushboo on 31 Oct 2022
Edited: Khushboo on 31 Oct 2022
Hello,
You can concatenate different columns in a table using MATLAB's strcat function as follows:
% Input table
imageFilename = {'Japan_001164_jpg.rf.c02ee7802c701e228f23a4033eb236c2.jpg'};
xmin = {384};
ymin = {313};
xmax = {415};
ymax = {406};
t1 = table(imageFilename, xmin, ymin, xmax, ymax);
% Create table with concatenated columns
concatenatedCols = strcat(t1.xmin, t1.ymin, t1.xmax, t1.ymax);
t2 = table(imageFilename, concatenatedCols);
Hope this answers your question!

Lei Hou
Lei Hou on 18 Nov 2022
Hi,
You can you mergevars to merge table variables.
>> t = table("Japan_001164_jpg.rf.c02ee7802c701e228f23a4033eb236c2.jpg",384,383,415,406,'VariableNames',["imageFileName" "xmin" "ymin" "xmax" "ymax"])
t =
1×5 table
imageFileName xmin ymin xmax ymax
__________________________________________________________ ____ ____ ____ ____
"Japan_001164_jpg.rf.c02ee7802c701e228f23a4033eb236c2.jpg" 384 383 415 406
>> mergevars(t,["xmin" "ymin" "xmax" "ymax"])
ans =
1×2 table
imageFileName Var2
__________________________________________________________ ________________________
"Japan_001164_jpg.rf.c02ee7802c701e228f23a4033eb236c2.jpg" 384 383 415 406

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!