How can I display data inside a table in expanded form?
Mostrar comentarios más antiguos
Greetings... I have a simple strcuture array (s) of two fields: name and data. Assume the array length is two. I wanted to display it in a table form in the command window. So, I used {struct2table} and generated a table T and displayed it in the command window. The problem is that, the table displays the data column in a collapsed form. Assume that s(1).data and s(2).data are (1 x 7) double arrays. The table displays them in that collapsed form: [1x7 double]. I want to expand each one inside the table and show it detailed, like [1.2 3.6 ...] in its place in the table. How can this be done? Thanks in advance.
4 comentarios
In general, the table is a (terribly handy) compositie data storage object and while it has convenient display features, it is NOT designed to be nor is it a general-purpose array viewer.
Walter Roberson
el 3 de Sept. de 2018
Editada: Walter Roberson
el 3 de Sept. de 2018
I could dig into the code and tell you which lines of @tabular/disp.m to change, but are you comfortable hacking Mathworks built in code, knowing that other code relies upon the current behaviour?
I do not recommend doing this. table() objects are not designed for display purposes. But if the question is whether it can be done, then the answer is that the supplied code cannot do it but that it is possible to hack it if you are really serious.
Mohamed Abd El Raheem
el 6 de Sept. de 2018
Editada: Mohamed Abd El Raheem
el 6 de Sept. de 2018
dpb
el 6 de Sept. de 2018
Well, Matlab is not a spreadsheet application; presentation is not it's strong suit.
Have you investigated the workspace variable viewer? It would show the elements of the field in the structure in a spreadsheet-like interface, but it can't place multiple variables on the same page such as what a table is able to consolidate.
Respuestas (1)
Walter Roberson
el 6 de Sept. de 2018
If you are only using table to display, then what you should be using instead is sprintf() or sprintf() with formats that include widths (possibly calculated) and possibly negative widths if you want left alignment.
>> sprintf('%-10s', 'hello')
ans =
'hello '
>> sprintf('%10s', 'hello')
ans =
' hello'
In particular, suppose you have a cell array column vector Names and a double array Values with the same number of rows.
ncol = size(Values,2);
fmt = ['%-15s ', repmat('%15g ', 1, ncol-1), '%15g\n'];
data = [Names, mat2cell(Values)] .'; %transpose is important
fprintf(fmt, data{:});
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!