フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by