フィルターのクリア

Changing values within a table

22 ビュー (過去 30 日間)
Mark Evans
Mark Evans 2021 年 3 月 20 日
編集済み: Mark Evans 2021 年 3 月 23 日
I want to make all weights (4th column) that are larger than 5 display the value 1 and all values below 5 to display 0.
This is what I have done so far, but it does not work.
T = table(column4); % Creating column table
A = table2array(T) % Converting table to an aray
A > 5
Thank you in advance!
  1 件のコメント
Star Strider
Star Strider 2021 年 3 月 20 日

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 3 月 20 日
編集済み: Cris LaPierre 2021 年 3 月 20 日
Try this.
trc = readtable("table1.csv");
trc.WEIGHT = trc.WEIGHT>5
A comment as well that I can't see what the full name of the 4th column is, so I assumed "WEIGHT". Update this code to match whatever the actual name is.
  2 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 3 月 20 日
編集済み: Cris LaPierre 2021 年 3 月 20 日
Your indexing is wrong. The use of dot notation already selects the 4th column (trc.WEIGHT). The curly braces in addition are not a valid syntax. See the table I linked to previousy for valid ways to access data in a table.
You probably want something that selects the column and then specific rows inside that column. The approach below creates a logical array to indicate which rows in trc.Type to extract.
extract = trc.Type(trc.Type == 'WED(R)')
You can learn more about logical arrays in Ch 12 of MATLAB Onramp.
Cris LaPierre
Cris LaPierre 2021 年 3 月 20 日
編集済み: Cris LaPierre 2021 年 3 月 20 日
You can add a second condition for the conditional statement to check using '&'.
extract = trc.Type(trc.Type == 'WED(R)' & trc.WEIGHT == 1)

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by