How to display a Table in LiveScript just the same way it is displayed upon defining it or calling it directly?
조회 수: 78 (최근 30일)
이전 댓글 표시
I'm working with tables in MATLAB LiveScript (.mlx files).
Mehtod 1. If I define a table (here: patients) and leave the semi-colon off, it shows a beautiful table in LiveScript. (and not in vanilla MATLAB, where the output will be just as in Method 3)
Method 2. If I 'call' a previously-defined table (again, patients), I get a warning that simply calling a variable is not the ideal practice and I should instead use disp for the same.
Method 3. But when I use disp to call a table, it does not show the table in the same way as in Method 1.
How do I display a previously-defined table in the same way as Method 1, without getting a warning like in Method 2?
LastName = ["Sanchez";"Johnson";"Zhang";"Diaz";"Brown"];
Age = [38;43;38;40;49];
Smoker = [true;false;true;false;true];
patients = table(LastName,Age,Smoker) %Method 1 example
%shows a beautiful 'table-like' table whose individual 'cells' can be
%selected, which also highlight the corresponding row (instance) and column
%(variable). Only applicable to Live Script. Else the output is the same as
%Method 3.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1174798/image.png)
disp(patients) %Method 3 example
%disp command shows a not so pretty, but seemingly terminal friendly table.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1174803/image.png)
댓글 수: 2
Walter Roberson
2022년 10월 31일
The case of assignment without semicolon is invoking @tabular/display if I recall correctly. Which is the same function as just listing the variable name. The difference is that the editor creates a warning (not error) if you do not use disp(). The editor will also warn if you call display() yourself.
The above is not intended to be a solution, just more detail about what is happening.
Yogesh R
2022년 11월 4일
편집: Yogesh R
2022년 11월 4일
![sample code](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1180563/sample%20code.png)
I am not getting any warning for simply calling the variable patients, even after enabling all warnings. I am not sure why you are getting it.
Anyways can you try using display instead of disp, and check if you are getting any warning.
P.S: Code was ran on MATLAB R2022b
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!