How to solve "Error using split First argument must be text"

51 ビュー (過去 30 日間)
BA
BA 2022 年 7 月 25 日
コメント済み: BA 2022 年 7 月 25 日
Having issues with my script. Everytime I run it, I get an error "Error using split. First argument must be text."
Stacked = readtable(root_folder 'Stacked.xlsx');
dates = Stacked.General_Prompt_SurveySubmittedDate_1;
c = split(dates, '/');
c(:, 3) = cellfun(@fliplr, c(:,3), 'UniformOutput', false);
datesNew = join(c, '/');
I'm not sure how to fix it. What I want to do is get the data to split and then flip all the years. Then I want to join it.
But I keep getting the error at the line "c=split..." so I'm not able to get it to run.
I have attached my dataset.
  1 件のコメント
Abderrahim. B
Abderrahim. B 2022 年 7 月 25 日
What are you trying to do with split function? dates doe not have / to split based on it!!

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 25 日
readtable is returning that column as datetime objects. You cannot split() datetime objects.
mask = dates < datetime(1000, 1,1);
dates(mask) = dates(mask) + calyears(2000);
No splitting or text processing necessary.
  1 件のコメント
BA
BA 2022 年 7 月 25 日
Thank you!! You're a legend mate. I've been trying to fix this for a while and didn't even realize that I couldn't split datetime. Thanks a ton

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by