フィルターのクリア

Append Row to bottom of table

11 ビュー (過去 30 日間)
Theodore
Theodore 2023 年 3 月 29 日
コメント済み: Peter Perkins 2023 年 4 月 5 日
I'd like to append a to a Nx4 table:
Name Amt Price Change
Pears 5 $1 $0.50
Apples 10 $1.5 $0.25
Such that it will add a row with the Name, but a '-' dash for the other three, which will be added with other logic.
For example adding Oranges would change the table to:
Name Amt Price Change
Pears 5 $1 $0.50
Apples 10 $1.5 $0.25
Oranges - - -
Thank you!

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 3 月 29 日
編集済み: Dyuman Joshi 2023 年 3 月 29 日
One of the ways to achieve the output you mentioned is to use string/cell/categorical data type for the variables as it is not possible to denote '-' i.e. a dash in numeric data type
%Categorical
Name = categorical(["Pears"; "Apples"]);
Amt = categorical(["5";"10"]);
Price = categorical(["$1";"$1.5"]);
Change = categorical(["$0.5";"$0.25"]);
y = table(Name,Amt,Price,Change)
y = 2×4 table
Name Amt Price Change ______ ___ _____ ______ Pears 5 $1 $0.5 Apples 10 $1.5 $0.25
var = categorical("-");
y(3,:) = {categorical("Orange"),var, var, var}
y = 3×4 table
Name Amt Price Change ______ ___ _____ ______ Pears 5 $1 $0.5 Apples 10 $1.5 $0.25 Orange - - -
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 3 月 29 日
Right.
To emphasize slightly: numeric variables cannot be set to be blank or to dash : if you need those output, you need to use one of char or string or categorical.
Peter Perkins
Peter Perkins 2023 年 4 月 5 日
Or to display with dollar signs, for that matter.
Teodore, to get what you are looking for, I recommend writing your own pretty-print function that does exactly what you need. That's kind of what Dyuman has done. Table display just isn't intended for that kind of output.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFinancial Data についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by