MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
____ ________ ______ ______ ______ ______ _____________

Adams 8235 'Female' false 66 137 22.112 127 83
Alexander 1300 'Male' true 69 171 25.252 128 99
Allen 7432 'Female' false 63 143 25.331 113 80
Anderson 1577 'Female' false 68 128 19.462 114 77
Bailey 2239 'Female' false 68 130 19.766 113 81

You also can reorder table variables by name. To reorder the table variables so that
Gender is last:

(^1) Find 'Gender' in the VariableNames property of the table.
(^2) Move 'Gender' to the end of a cell array of variable names.
(^3) Use the cell array of names to reorder the table variables.
varnames = T.Properties.VariableNames;
others = ~strcmp('Gender',varnames);
varnames = [varnames(others) 'Gender'];
T = T(:,varnames);
Display the first five rows of the reordered table.
T(1:5,:)
ans=5×7 table
ID Smoker Height Weight BMI BloodPressure Gender




Adams 8235 false 66 137 22.112 127 83 'Female'
Alexander 1300 true 69 171 25.252 128 99 'Male'
Allen 7432 false 63 143 25.331 113 80 'Female'
Anderson 1577 false 68 128 19.462 114 77 'Female'
Bailey 2239 false 68 130 19.766 113 81 'Female'
Write Table to File
You can write the entire table to a file, or create a subtable to write a selected portion of
the original table to a separate file.
Write T to a file with the writetable function.
writetable(T,'allPatientsBMI.txt');
9 Tables

Free download pdf