How can I add a column to a table / add a variable to a table?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi there, I want to add columns to a table which seems to be impossible by default. I created a workaround to do this but I wonder if there is a more straightforward way to do this? Thanks very much for your help!
Here's the code:
clear all, clc;
% the point of this script is to analyze region properties of a
% binary image and write them to a file. However, more columns
% should be added before.
% read coins sample and analyze region properties
imageName = 'coins.png';
I = im2bw(imread(imageName));
Cstruct = bwconncomp(I,8);
LC = labelmatrix(Cstruct);
ObjectInfo = regionprops(Cstruct, {'Area','Centroid'});
% Problem:
% it is not possible to add another variable to ObjInfo
% like ObjInfo.newCol = 1:length(ObjectInfo)
% create Table from Results
ObjTable = struct2table(ObjectInfo);
% I want to add columns to the table.
% But adding columns to a table is not possible.
% this is a dirty workaround
ObjTable.rowID = cellstr(num2str(ObjTable.Area));
ObjTable.sampleID = ObjTable.rowID;
ObjTable.imgID = ObjTable.rowID;
a = ObjTable.rowID;
b = ObjTable.sampleID;
c = ObjTable.imgID;
for m=1:numel(a)
a(m) = {m};
b(m) = cellstr(imageName);
c(m) = cellstr(imageName);
end
ObjTable.rowID = a;
ObjTable.sampleID = b;
ObjTable.imgID = c;
clear a b c m;
% done
ObjTable
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!