How can I put an array containg multiple numbers into a matlab table?
47 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
dpb
2023-2-18
编辑:dpb
2023-2-18
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 个评论
Star Strider
2023-2-18
编辑:Star Strider
2023-2-18
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!