how to display data in a variable in the table using the uitable vertically(columnwise)?

hello, i want to create a table using uitable function that takes the name of the students from the .mat variable in the workspace and display it in the table vertically. i can retrieve the data but it is displayed in a single row(horizontally). the variable contains 5 names which should be displayed vertically but it is displaying horizontally. can anybody tell me how to edit the table so that it displays the data vertically. I attach the demo code of what is happening here. plz repli as soon as possi.......
f = figure('Position',[100 100 400 150]);
load PersonName; %.mat file containing the names of student.
date=datestr(now,'dd');
columnname = {'StudentID', 'StudentName', date};
columnformat = {'char', 'bank', 'char'};
columneditable = [true true true];
t = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9],...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'RowName',[],'Data',sname);

댓글 수: 1

i want to add a new column in the table that is appended to the table with the columnname as the system current date as it shown in the code for the current date. but it should add another column for the next day rather than updating the same column. please help me how to do that... the code which i have is as under.
f = figure('Position',[200 200 700 450]); % load PersonName; %.mat file containing the names of student.
personNames = {'s1','s2','s3','s4','s5','s6','s7','s8','s9','s10',... 's11','s12','s13','s14','s15','s16','s17','s18','s19','s20',... 's21','s22','s23','s24','s25','s26','s27','s28','s29','s30',... 's31','s32','s33','s34','s35','s36','s37','s38','s39','s40'}; idNumbers = [1, 2, 3, 4, 5, 6,7,8,9,10,... 11,12,13,14,15,16,17,18,19,20,... 21,22,23,24,25,26,27,28,29,30,... 31,32,33,34,35,36,37,38,39,40]; date=datestr(now,'dd/mm/yyyy'); %system current date as column numberOfRows = length(idNumbers); dataTable = cell(numberOfRows, 3); for row = 1 : numberOfRows dataTable{row, 1} = idNumbers(row); dataTable{row, 2} = personNames{row}; dataTable{row, 3} = 'Present'; end columnname = {'StudentID', 'StudentName',date}; columnformat = {'char', 'char', 'char'}; columneditable = [true true true]; t = uitable('Units','normalized','Position',... [0.1 0.1 0.9 0.9],... 'ColumnName', columnname,... 'ColumnFormat', columnformat,... 'ColumnEditable', columneditable,... 'RowName',[],... 'Data',dataTable);
i want to add new column dynamically in the table when the date changes from the previous system date to the next date. please help me.. rpli neede very soon...thank u.

댓글을 달려면 로그인하십시오.

 채택된 답변

You need to create sname from whatever PersonName loads into memory.
f = figure('Position',[100 100 400 150]);
% load PersonName; %.mat file containing the names of student.
personNames = {'Abert Einstein', 'Robert Oppenhemimer', 'Isaac Newton', ...
'James Clerk Maxwell', 'Linus Pauling', 'Steven Hawking'};
idNumbers = [1, 2, 3, 4, 5, 6];
numberOfRows = length(idNumbers);
dataTable = cell(numberOfRows, 2);
for row = 1 : numberOfRows
dataTable{row, 1} = idNumbers(row);
dataTable{row, 2} = personNames{row};
end
columnname = {'StudentID', 'StudentName'};
columnformat = {'char', 'bank', 'char'};
columneditable = [true true true];
t = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9],...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'RowName',[],...
'Data',dataTable);

댓글 수: 3

Thank u very much for the help. this would help me a lot.
i want to add a new column in the table that is appended to the table with the columnname as the system current date as it shown in the code for the current date. but it should add another column for the next day rather than updating the same column. please help me how to do that... the code which i have is as under.
f = figure('Position',[200 200 700 450]); % load PersonName; %.mat file containing the names of student.
personNames = {'s1','s2','s3','s4','s5','s6','s7','s8','s9','s10',... 's11','s12','s13','s14','s15','s16','s17','s18','s19','s20',... 's21','s22','s23','s24','s25','s26','s27','s28','s29','s30',... 's31','s32','s33','s34','s35','s36','s37','s38','s39','s40'}; idNumbers = [1, 2, 3, 4, 5, 6,7,8,9,10,... 11,12,13,14,15,16,17,18,19,20,... 21,22,23,24,25,26,27,28,29,30,... 31,32,33,34,35,36,37,38,39,40]; date=datestr(now,'dd/mm/yyyy'); %system current date as column numberOfRows = length(idNumbers); dataTable = cell(numberOfRows, 3); for row = 1 : numberOfRows dataTable{row, 1} = idNumbers(row); dataTable{row, 2} = personNames{row}; dataTable{row, 3} = 'Present'; end columnname = {'StudentID', 'StudentName',date}; columnformat = {'char', 'char', 'char'}; columneditable = [true true true]; t = uitable('Units','normalized','Position',... [0.1 0.1 0.9 0.9],... 'ColumnName', columnname,... 'ColumnFormat', columnformat,... 'ColumnEditable', columneditable,... 'RowName',[],... 'Data',dataTable);
i want to add new column dynamically in the table when the date changes from the previous system date to the next date. please help me.. rpli neede very soon...thank u.
Same concept. You need to build the cell array with whatever rows and columns you want, then use set() to set the 'data' property of the table to your cell array.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by