필터 지우기
필터 지우기

How can I add a column to a table / add a variable to a table?

조회 수: 2 (최근 30일)
Jakob Nikolas
Jakob Nikolas 2014년 5월 3일
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by