How can I put an array containg multiple numbers into a matlab table?
조회 수: 66 (최근 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에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!