How can I put an array containg multiple numbers into a matlab table?

64 visualizzazioni (ultimi 30 giorni)
I'm getting trouble in generating a 'table' variable for my object detection program, and here's my problem:
I want to create a table that contains the file path and bouding box coordinates like this in a matlab example
However, I don't know how to put an array that contains 4 numbers into one column in matlab table object. I have successfully created a cell obejct like this, but when I use the cell2table function to convert it into table object, it looks like this......
So I would really like to know how I can create a table like it is in the first picture, and here's my code, thanks very much!
bndbox = table2array(framedata(:,2:5));
filename = table2array(framedata(:,1));
temp = cell(length(filename),2);
for i=1:length(filename)
temp(i,1) = {filename(i)};
temp(i,2) = {[bndbox(i,1),bndbox(i,2),bndbox(i,3),bndbox(i,4)]};
end
table = cell2table(temp);
ps: The original data is also a table object but with 4 coordinate numbers in different columns

Risposte (2)

dpb
dpb il 18 Feb 2023
Modificato: dpb il 18 Feb 2023
Just use <table> directly to insert variables to a table...
files={'filename01.ext';'filename02.ext'};
coords=[randi(1000,1,4);randi(1000,1,4)]; % make up something similar
tT=table(files,coords,'VariableNames',{'ImageFile','Coordinates'}) % put into a table
tT = 2×2 table
ImageFile Coordinates __________________ ________________________ {'filename01.ext'} 730 755 863 756 {'filename02.ext'} 605 505 967 577
tT.Coordinates(2,3) % address a given row, column coordinate % reference a specific coordinate value
ans = 967

Star Strider
Star Strider il 18 Feb 2023
Modificato: Star Strider il 18 Feb 2023
Put the bounding box coordinates in a cell array —
for k = 1:5
imageFiles(k,:) = sprintf('vehicleImages/image%05d.jpg',k);
end
vehicle = compose('%03d,%03d,%03d,%03d', randi([100 999],5,4));
VehicleImages = table(imageFiles,vehicle)
VehicleImages = 5×2 table
imageFiles vehicle ____________________________ ___________________ vehicleImages/image00001.jpg {'665,966,527,876'} vehicleImages/image00002.jpg {'328,242,615,292'} vehicleImages/image00003.jpg {'664,338,503,145'} vehicleImages/image00004.jpg {'398,244,399,363'} vehicleImages/image00005.jpg {'444,153,102,527'}
writetable(VehicleImages,'VehicleImageInfo.txt') % Write 'table' To File
VehicleImageData = readtable('VehicleImageInfo.txt') % Read File To 'table'
VehicleImageData = 5×2 table
imageFiles vehicle ________________________________ ___________________ {'vehicleImages/image00001.jpg'} {'665,966,527,876'} {'vehicleImages/image00002.jpg'} {'328,242,615,292'} {'vehicleImages/image00003.jpg'} {'664,338,503,145'} {'vehicleImages/image00004.jpg'} {'398,244,399,363'} {'vehicleImages/image00005.jpg'} {'444,153,102,527'}
image_file_names = cell2mat(VehicleImageData.imageFiles) % Character Array Of File Names
image_file_names = 5×28 char array
'vehicleImages/image00001.jpg' 'vehicleImages/image00002.jpg' 'vehicleImages/image00003.jpg' 'vehicleImages/image00004.jpg' 'vehicleImages/image00005.jpg'
vehicle = cell2mat(cellfun(@str2double,cellfun(@(x)strsplit(x,','), VehicleImageData.vehicle, 'Unif',0),'Unif',0)) % 'vehicle' Bounding Box Matrix
vehicle = 5×4
665 966 527 876 328 242 615 292 664 338 503 145 398 244 399 363 444 153 102 527
There are likely several ways to do this. I chose the compose function here.
EDIT — Added writetable and readtable calls to test it, and associated functions to retrieve the necessary information.
.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by