Help Changing Class/Type In A Table

5 ビュー (過去 30 日間)
Kristine
Kristine 2025 年 5 月 28 日
コメント済み: Kristine 2025 年 6 月 4 日
Hi y'all,
How do I change the class/type of values in a column into datetime? They were added as datetime going in. When I go to access the file after and check the class, it indicates the variables are catigorical. Why does this happen?
Thank you!
  8 件のコメント
Cris LaPierre
Cris LaPierre 2025 年 6 月 4 日
編集済み: Cris LaPierre 2025 年 6 月 4 日
new_table = new_table_useful_data(with_datetime) ;
no_zeroz = remove_zeros(new_table) ;
no_ESD_over_150 = remove_ESD_greater_150(no_zeroz) ;
These 3 data processing functions are also not defined in the shared code either.
Kristine
Kristine 2025 年 6 月 4 日
These were other functions that remove rows of data that are unrelated to adding datetime columns to the files.
But I did resolve my own issue by switching "MM-dd-yyyy" to "MM/dd/yyyy". I changed nothing else. Now the columns are interpreted as having datetime values. A frustratingly simple solution, though I still don't understand why my code didn't work this way before.

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2025 年 5 月 29 日
The best solution would be to fix how your data is imported. Then you don't hvae to convert it.
You could use convertvars, or just use datetime directly on the table variable
T.A = datetime(T.A,'InputFormat',infmt)
infmt should be set to match the current data. Since your data is categorical, you likely first need to convert it to a string or numeric data type. We could be more specific if you shared your data and code.
  8 件のコメント
Kristine
Kristine 2025 年 6 月 4 日
@Cris LaPierre This is just a simplification on my code, but still results in a column of categorical values instead of datetime for me.
Cris LaPierre
Cris LaPierre 2025 年 6 月 4 日
This code does not create categorical values. The code out.DateOnly.Format would throw an error. Are you sure the values are categoricals?
Can you identify where your code diverges from this example? Better yet, share your implementation of this approach.

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

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by