필터 지우기
필터 지우기

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
patients = 5×3 table
LastName Age Smoker _________ ___ ______ "Sanchez" 38 true "Johnson" 43 false "Zhang" 38 true "Diaz" 40 false "Brown" 49 true
%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.
disp(patients) %Method 3 example
LastName Age Smoker _________ ___ ______ "Sanchez" 38 true "Johnson" 43 false "Zhang" 38 true "Diaz" 40 false "Brown" 49 true
%disp command shows a not so pretty, but seemingly terminal friendly table.
  댓글 수: 2
Walter Roberson
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
Yogesh R 2022년 11월 4일
편집: Yogesh R 2022년 11월 4일
sample code
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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by