フィルターのクリア

Overwrite table data if the logical index of row is true.

1 回表示 (過去 30 日間)
Smithy
Smithy 2022 年 8 月 26 日
コメント済み: Smithy 2022 年 8 月 26 日
Hello everybody,
I would like to overwrite the table data if the logical index of row is true.
Logical index will be ture if sampleinput.TEST_ITEM1 is'TV'
Then, the sampleinput.TEST_LOAD1 need to be changed with sampleinput.TEST_LOAD0
If sampleinput.TEST_ITEM1 is not 'TV' and then keep sampleinput.TEST_LOAD1 data.
Please give me some help.
load sample
k = contains(sampleinput.TEST_ITEM1,'TV'); % logical indexing
sampleinput.TEST_LOAD1(k) = sampleinput.TEST_LOAD0(k);

採用された回答

Chunru
Chunru 2022 年 8 月 26 日
load(websave("sample.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1108480/sample.mat"))
sampleinput
sampleinput = 11×3 table
TEST_ITEM1 TEST_LOAD0 TEST_LOAD1 __________ __________ __________ {'TV'} 110 {'355'} {'TV'} 550 {'355'} {'TV'} 220 {'355'} {'TT'} 660 {'355'} {'TV'} 330 {'355'} {'TV'} 770 {'355'} {'TV'} 440 {'355'} {'TV'} 880 {'355'} {'TL'} NaN {'355'} {'TL'} NaN {'355'} {'TL'} NaN {'355'}
idx = sampleinput.TEST_ITEM1 == "TV";
sampleinput.TEST_LOAD1(idx) = cellstr(string(sampleinput.TEST_LOAD0(idx)))
sampleinput = 11×3 table
TEST_ITEM1 TEST_LOAD0 TEST_LOAD1 __________ __________ __________ {'TV'} 110 {'110'} {'TV'} 550 {'550'} {'TV'} 220 {'220'} {'TT'} 660 {'355'} {'TV'} 330 {'330'} {'TV'} 770 {'770'} {'TV'} 440 {'440'} {'TV'} 880 {'880'} {'TL'} NaN {'355'} {'TL'} NaN {'355'} {'TL'} NaN {'355'}
  1 件のコメント
Smithy
Smithy 2022 年 8 月 26 日
thank you vey much. It works really well.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by