Clear Filters
Clear Filters

Align table data to the left

7 views (last 30 days)
Asi
Asi on 15 Oct 2023
Answered: Walter Roberson on 15 Oct 2023
Is there a way to align table data to the left?
Code:
clc;
clear all;
close all;
LastName = ["Sanchez";"Johnson";"Zhang";"Diaz";"Brown"];
Age = [38;43;38;40;49];
HeightPerson = [71;69;64;67;64];
Weight = [176;163;131;133;119];
patients = table(LastName,Age,HeightPerson,Weight)
  1 Comment
Dyuman Joshi
Dyuman Joshi on 15 Oct 2023
I'm not sure if that can be done for table arrays. Any particular reason why you want to align the table data to the left?
It can be done for uitables though.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 15 Oct 2023
Yes.
You could copy all of the code having to do with implementing tables. Then modify it so that tables inherit from matlab.mixin.CustomDisplay . Then use the facilities described in https://www.mathworks.com/help/matlab/matlab_oop/custom-display-interface.html to customize the display of table entries
Be careful that you also track down all of the classes and functions that create table objects, including timetable2table() and regionprops(), and modify them to invoke your new table-equivalent class instead of the built-in table class instead.
I would suggest to you that it would be rather a lot easier to create your own displaytable() function that took at table and formatted it however you want. The difference would be that you would only get the desired output if you specifically requested it, instead of by default.
You could also investigate creating your own @tabular/display.m but I am not clear as to whether that would interfere with other uses of tables.

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!