Displaying MATLAB tables wrapped
Show older comments
I only starting using the MATLAB datatype, table, a few years ago but have always been annoyed that when I display a table in MATLAB, if you have many fields, the display runs off the right side of the command window display and you have to scroll right to see other columns (other fields). I recently had to step back to MATLAB 2014 in a specific setting and starting using tables in that envronment as well. The function, head did not exist back then but I could do something similar with:
disp(TBL(1:6,:));
And wouldn't you know it,the display actually wrapped at the end of the command window such that I did not have to scroll to the right to see what I needed ... I only needed to scroll up and down. With no success, I have searched and searched the settings for a switch to make table display wrap. Does anyone know if there is a setting that wraps table display? Thanks, Dan
3 Comments
dpb
on 30 Jun 2023
I don't think there is such a setting, no.
The closest I think you could come without writing code would be something like your above, but
disp(TBL{1:N,:})
and that has two significant limitations--
- All variables have to be of the same type/size so can be catenated into an array, and
- Lose the table variable headings.
But, there's no user control over the table output format other than for the individual values that follow the global setting as set by format command/function.
In general, in practice I've found that generally am only interested in a subset of variables so what I tend to do is to define a subset array of column indices/variable names and use it instead to only display those of current interest. That doesn't help if more than what will fit on the monitor are actually of interest/needed, of course.
Catalytic
on 3 Jul 2023
Why is scrolling up and down better than scrolling left to right? Generally, computer monitors are wider than they are tall, so you will have to do more up-down scrolling for wrapped output than unwrapped.
Dan
on 3 Jul 2023
Answers (1)
One possibility,
TBL=array2table(rand(4,12));
wrapit(TBL)
function wrapit(T,ncols)
if nargin<2, ncols=7; end
M=ceil(width(T)/ncols);
for i=1:M
k=min(ncols,width(T));
t=T(:,1:k); T(:,1:k)=[];
disp(t)
end
end
Categories
Find more on Logical 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!