How to merge cells within a table
Show older comments
I have a data table in which I am expanding with calcualtions. I want to have a column that merges the sequential even with its subsequent odd.

I want column 6 to have the bordered cells merged with a result of a calculation inside. Is this possible? I've seen 2 column headers merged into one with 2 separate columns underneath (see Temperature in image below). I would assume something similar could be done. Thanks in advance for any help.

Accepted Answer
More Answers (1)
Peter Perkins
on 9 Jun 2017
0 votes
David, this is certainly possible, but you have not said what you want done with the other variables in the table. Guillaume has provided a solution that merged each odd/even pair into a variable that's half the height of the original, and then broadcasts that out into the original as duplicate pairs of values. It sounds like that's not what you want. What do you want as the result?
7 Comments
David Stolnis
on 12 Jun 2017
Guillaume
on 12 Jun 2017
No, it's really not possible.
On the back end, tables require that all variables (columns) have the same number of rows. So you could not even store a variable that span multiple rows.
Since the back end does not allow it, the only way this could work would be to do this at the display level, merging rows of a variable that are identical. However, this is not something that is supported by the variable editor.
You would really need a new type of class or seriously complicate the current table class in order to support this, plus some improvement to the variable editor. The new class, you could implement at the m level (as table currently is) but the variable editor would needs modification of matlab executable.
David Stolnis
on 15 Jun 2017
Guillaume
on 15 Jun 2017
Note: the following is just my opinion, I don't work for Mathworks, don't know what their plans are, and I certainly don't speak for them.
I don't think what you want fits the concept of tables, which to me match very much the database design where all rows and columns have the same size.
What you want is more like a grid with cells of varying sizes. With that design you can't really have a concept of rows or columns as a particular cell may span several rows or columns. While it may make for some fancy display it would also make manipulating the data a lot harder. As a result, I don't see this being implemented. Certainly not as part of the table design.
Peter Perkins
on 19 Jun 2017
Perhaps I've misunderstood the question. It is possible as long as you create a variable with two columns in the output table, or a variable that is a cell array, each cell of which contains a two-element vector. Maybe that's not what you're looking for, but David, you still haven't shown a concrete example.
Guillaume
on 19 Jun 2017
My understanding is that David wants some cells of the table to span more than one row or column. Similar to the rowspan or colspan of an html table or the merge cell feature of Excel.
That's the way I interpret the 1st illustration in the question. Column 60 would have half the number of elements as the other columns, with 1st element shared between row 1 and 2 of the other columns, 2nd element shared between row 3 and 4, etc.
Peter Perkins
on 20 Jun 2017
OK, I get it. That's not possible.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!