For loop to enter data into a Cell array by calling functions. Creating an array with 'n' number of rows. Displaying content onto a uitable
2 views (last 30 days)
Show older comments
Hello Everyone,
I'm trying to make a simple student database. I'm trying to display the data onto a uitable. Now my problem is how do I make this program run 'n' number of times and store the data into a new row every time data is added. eg when 2 students are selected to be in a specific course, there would be 2 rows in the uitable with the 2 students' names. Here's the main script file:
*disp('Welcome To The Student Directory')
e = menu(' ');
p = numbers; %function to ask how many students
for x=1:p
if e == 1
Cell = {name,ID,total}; %functions for the name, ID, and total marks (which contains CW and final marks functions etc) end
if e == 2
Cell = {ID,name,total};
end
end
a = uitable;
fprintf('Thank you for using our program \n A window will open displaying the Students Name alongwith their total marks and Grade \n')
ColName = {'Name','ID','Total Marks','Grades'};
uitable('ColumnName',ColName,'Data',Cell);*
oh and I thought of making a vector for EACH of the functions (eg name, ID, total, etc) but then if the number of students selected is 5, the function will ask for ALL 5 names before moving onto ID and so on.
How do i make it loop ALL the functions 'n' number of times (i.e. 'n' students) and store it onto a cell array with one row displaying all the data for ONE student? I'm new to MATLAB :( any help would be greatly appreciated :)
Thanks so much for your time !
2 Comments
Oleg Komarov
on 3 Jun 2011
Please format the code: http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question
Answers (1)
Brian Cody
on 6 Jun 2011
Hi Harith,
You probably want something like this:
for row=1:nStudents
Cell{row, 1} = Name;
Cell{row, 2} = ID;
Cell{row, 3} = Total;
% Do this for all values in a given row.
end
Bear in mind that a uitable cannot display data that is in a structure array. It can only display numeric, logical, or cell data. And if you are using a cell array for your data, that cell array must contain only numeric, logical, or string values.
I hope this helps!
-Brian
0 Comments
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!