1、f = figure('Position', [100 100 752 250]);
2、t = uitable('Parent', f, 'Position', [25 50 700 200], 'Data', magic(10))
3、load patients LastName Age Weight Height SelfAssessedHealthStatus % load dataPatientData = [LastName num2cell([Age Weight Height]) SelfAssessedHealthStatus]; % convert to cell arrayt.Data = PatientData;
4、t.ColumnName = {'雉搽妤粲LastName', 'Age', 'Weight', 'Hei爿讥旌护ght', 'Self Assessed|Health Status'};
5、t.ColumnWidth = {100, 'auto', 'auto', 'auto', 150};
6、t.RowName = [];
7、t.Position = [15 25 495 200];
8、t.BackgroundColor = [.4 .4 .4; .4 .4 .8]; t.ForegroundColor = [1 1 1];
9、t.ColumnEditable = [false true true true true];
10、t.ColumnFormat = {[] [] [] [] {'Excellent', 'Fair', 'Good', 'Poor'}};
11、t.CellEditCallback = 氆尧彻性@ageCheckCB;function ageCheckCB(src, eventdata)if (eventdata.Indices(2) == 2 && ... % check if column 2 (eventdata.NewData < 0 || eventdata.NewData > 120)) tableData = src.Data; tableData{eventdata.Indices(1), eventdata.Indices(2)} = eventdata.PreviousData; src.Data = tableData; % set the data back to its original value warning('Age must be between 0 and 120.') % warn the userendend
12、get(t)