How can I put an array containg multiple numbers into a matlab table?
9 views (last 30 days)
Show older comments
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

0 Comments
Answers (2)
dpb
on 18 Feb 2023
Edited: dpb
on 18 Feb 2023
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.Coordinates(2,3) % address a given row, column coordinate % reference a specific coordinate value
0 Comments
Star Strider
on 18 Feb 2023
Edited: Star Strider
on 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)
writetable(VehicleImages,'VehicleImageInfo.txt') % Write 'table' To File
VehicleImageData = readtable('VehicleImageInfo.txt') % Read File To 'table'
image_file_names = cell2mat(VehicleImageData.imageFiles) % Character Array Of File Names
vehicle = cell2mat(cellfun(@str2double,cellfun(@(x)strsplit(x,','), VehicleImageData.vehicle, 'Unif',0),'Unif',0)) % 'vehicle' Bounding Box Matrix
EDIT — Added writetable and readtable calls to test it, and associated functions to retrieve the necessary information.
.
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!