How to create a table and add elements to the table in MATLAB?
Show older comments
I want to create a 10X10 table and add elements to the table. Rows and columns both are having entries 1 2 3 4 5 6 7 8 9 10] and also for binary entries as [ 001; 010; 110; 101; 210; 220; 002; 202; 222; 111]
e.g. I want to add elements under all the pairs of rows and columns like (1,1) (1,2).............................................(10,1)........... (10,10)
How can I add 'lambda' under these pairs of rows and columns using MATLAB?
Kindly tell
Regards
Surabhi
4 Comments
surabhi sachdeva
on 12 Oct 2017
dpb
on 12 Oct 2017
Sorry, can't understand the issue you're having. You can't add a variable to a table without having values for all rows, though; it has to be a rectangular structure.
Show us a small subset of the problem -- what you have and what you'd like the result to be (and logic to get the latter from the former).
surabhi sachdeva
on 13 Oct 2017
Accepted Answer
More Answers (1)
Guillaume
on 13 Oct 2017
If you do want to create tables as opposed to datasets, here is how I'd do it:
states = 0:8;
rownames = compose('%d', states);
varnames = compose('t_%d', states);
mytable = cell2table(cell(numel(states)), 'VariableNames', varnames, 'RowNames', rownames)
I'm not sure what your question is exactly, if you're looking to put a value in a particular cell of the table, you can use any number of syntaxes:
mytable(5, 6) = {'001'}; %using normal indices as for matrices
mytable('2', 't_4') = {'100'} %using row and var names
mytable.t_3(5) = {'101'};
1 Comment
Walter Roberson
on 13 Oct 2017
The user is using R2013a, which is the release before table objects were added.
Categories
Find more on Labels and Annotations 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!