Merge the multi-columns, multi-rows in one column, one row

5 Ansichten (letzte 30 Tage)
abdullah al-dulaimi
abdullah al-dulaimi am 30 Okt. 2022
Beantwortet: Chunru am 31 Okt. 2022
4755×5 table
filename xmin ymin xmax ymax
________________________________________________________ ____ ____ ____ ____
Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg 0 238 150 415
Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg 96 287 414 319
Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg 22 296 95 311
Result will be
filename Damage
________________________________________________________ _________________________________
Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg [0,238,150,415; 96, 287, 414, 319; 22, 296, 95 ,311]]

Antworten (1)

Chunru
Chunru am 31 Okt. 2022
var = ["filename", "xmin", "ymin", "xmax", "ymax"]
var = 1×5 string array
"filename" "xmin" "ymin" "xmax" "ymax"
T = {
"Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg", 0, 238, 150, 415;
"Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg", 96, 287, 414, 319;
"Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg", 22, 296, 95, 31};
T =cell2table(T, "VariableNames", var);
ufn = unique(T.filename);
Res = [];
for i=1:length(ufn)
tmp.filename = ufn(i);
tmp.Damage = T{T.filename == ufn(i), 2:5};
Res = [Res; struct2table(tmp, 'AsArray', true)];
end
Res
Res = 1×2 table
filename Damage __________________________________________________________ ____________ "Japan_000001_jpg.rf.7b3ecaac169c998a18815a31934dbbea.jpg" {3×4 double}
Res.Damage{1}
ans = 3×4
0 238 150 415 96 287 414 319 22 296 95 31

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by