![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/719889/image.png)
csvインポート時に、日付をシリアル値でインポートしたい
조회 수: 10 (최근 30일)
이전 댓글 표시
csvをインポートする際に、日付の列のみをシリアル値で読み込みたいのですが、方法が分かりませんでした。
行列、テーブル双方の場合でも可能な場合、それぞれの方法をご教示頂けますと嬉しいです。
現状思いつくのですと、以下のような手順になり、もっと簡単な方法がないかと思っています。
①csvをtableでインポート(日付はdatetime指定)
②日付をdatenumでシリアル値に変換
③日付以外のデータと再度合体
댓글 수: 0
채택된 답변
Hernia Baby
2021년 8월 24일
楽したいのでアプリを活用します
以下のコードはインポート機能を使ってそれをライブスクリプト化したものです
MATLABのフォルダーからBook4.csvをダブルクリックしてインポートアプリを立ち上げてください
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/719889/image.png)
ライブスクリプトの生成で以下のコードが生成されます
opts = delimitedTextImportOptions("NumVariables", 6, "Encoding", "UTF-8");
% 範囲と区切り記号の指定
opts.DataLines = [2, Inf];
opts.Delimiter = ",";
% 列名と型の指定
opts.VariableNames = ["Ping_index", "Distance_gps", "Distance_vl", "Ping_date", "Ping_time", "Ping_milliseconds"];
opts.VariableTypes = ["double", "double", "double", "datetime", "datetime", "double"];
% ファイル レベルのプロパティを指定
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% 変数プロパティを指定
opts = setvaropts(opts, "Ping_date", "InputFormat", "yyyy/MM/dd");
opts = setvaropts(opts, "Ping_time", "InputFormat", "HH:mm:ss");
% データのインポート
Book4 = readtable("Book4.csv", opts);
% 一時変数のクリア
clear opts
ここでシリアル値を付け加えます(コードを書いたのはここだけ)
Book4.Ping_date_S = datenum(Book4.Ping_date);
Book4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 スプレッドシート에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!