How can I clear an entire table column without deleting the variable?

26 ビュー (過去 30 日間)
s.h.m_89
s.h.m_89 2018 年 5 月 23 日
コメント済み: s.h.m_89 2018 年 6 月 13 日
I have the following table and want to clear the variable P without deleting the variable. Is there a way how I can do that or should I just delete the variable by using removevars and add new data by 'new' variable P.
P Type Date
0,43008 'Feeder' '21.05.2018'
0,03786 'Feeder' '21.05.2018'
0,37238 'Loader' '21.05.2018'
...
(288x4 table)
Thanks in advance!
  1 件のコメント
Stephen23
Stephen23 2018 年 5 月 23 日
@s.h.m_89: what do "cleared" numeric values look like? What value/s would they have?

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

採用された回答

Peter Perkins
Peter Perkins 2018 年 6 月 4 日
The short answer is to just overwrite the entire variable:
t.P = NaN(size(T.P))
You could also overwrite every element
t.P(:) = NaN
but there's not much advantage. In recent versions of MATLAB, you can assign missing:
t.P(:) = missing
but if you know the var is numeric, NaN is just as good. But missing works on other data types too, like categorical, datetime, ... . If you need to clear out variables of different types, using missing avoids a switch on the type.
By the way, you should consider making Type a categorical, and making Date a datetime. You may have already done that.

その他の回答 (1 件)

sloppydisk
sloppydisk 2018 年 5 月 23 日
You can simply overwrite the values by indexing with curly braces if that is what you want
t = table(rand(6, 1), rand(6, 1), rand(6, 1))
t{:, 1} = (1:6)';
  4 件のコメント
s.h.m_89
s.h.m_89 2018 年 5 月 28 日
編集済み: s.h.m_89 2018 年 5 月 28 日
Thanks everyone for your quick responses. @Jeff I did as you recommended. Many thanks!
Walter Roberson
Walter Roberson 2018 年 5 月 28 日
NaN is the indicator of Missing for numeric entries for the purposes of tables. https://www.mathworks.com/help/matlab/ref/ismissing.html

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by