MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

number of columns and the contents of its cells can be concatenated onto the
corresponding table variables.


cellPatients = {'Edwards','Male',42,70,158,0,116,83;
'Falk','Female',28,62,125,1,120,71};
Tnew = [Tnew;cellPatients];
size(Tnew)


ans = 1×2


106 8


You also can convert a cell array to a table using the cell2table function.


Add Rows from Structure


You also can append new rows stored in a structure. Convert the structure to a table, and
then concatenate the tables.


structPatients(1,1).LastName = 'George';
structPatients(1,1).Gender = 'Male';
structPatients(1,1).Age = 45;
structPatients(1,1).Height = 76;
structPatients(1,1).Weight = 182;
structPatients(1,1).Smoker = 1;
structPatients(1,1).Systolic = 132;
structPatients(1,1).Diastolic = 85;


structPatients(2,1).LastName = 'Hadley';
structPatients(2,1).Gender = 'Female';
structPatients(2,1).Age = 29;
structPatients(2,1).Height = 58;
structPatients(2,1).Weight = 120;
structPatients(2,1).Smoker = 0;
structPatients(2,1).Systolic = 112;
structPatients(2,1).Diastolic = 70;


Tnew = [Tnew;struct2table(structPatients)];
size(Tnew)


ans = 1×2


108 8


Add and Delete Table Rows
Free download pdf