string形式のファイル名の作成
21 views (last 30 days)
Show older comments
csv形式のファイルからデータをインポートして、処理した上でcsvファイルと同じファイル名のxlsxファイルの作成を考えております。
file = "C:\asdf.csv";
[filepath,name,ext] = fileparts(file)
としてcsvのファイル名をstring形式で取り込み
処理したデータTを
writetable(T,name.xlsx)
とすればできるのではないか考えたのですができませんでした。
良い方法があれば教えていただけないでしょうか?
4 Comments
Atsushi Ueno
on 3 Jul 2022
そういう事でしたか。それならこれでファイル名の拡張子だけ変更して保存する事が出来ます
file = "C:\asdf.csv";
[filepath,name,ext] = fileparts(file)
writetable(T,[filepath,name,'.xlsx']);
Accepted Answer
Hernia Baby
on 4 Jul 2022
エラー: writetable (line 152)
FILENAME は空でない文字ベクトルまたは string スカラーでなければなりません。
---------------------------------------------------
file = "C:\asdf.csv";
[filepath,name,ext] = fileparts(file)
以下がcatでの連結です
[filepath,name,'.xlsx']
以下がappendでの連結です
filepath + name + '.xlsx'
2 Comments
Atsushi Ueno
on 4 Jul 2022
system('cat /proc/version');
厳密に言うとCドライブが無い事が原因ではなく、Linuxプラットフォームではfileparts関数がファイルパスの区切り文字としてスラッシュ(/)しか受け付けない事が原因ですね。Windowsプラットフォームではスラッシュ(/)もバックスラッシュ(\)も使えるので、fileparts関数は両方とも使えると勘違いしていました。
% On Microsoft Windows systems, you can use either forward (/) or back (\) slashes
% as path delimiters, even within the same path. On Unix and Macintosh systems, use
% only / as a delimiter.
More Answers (2)
See Also
Categories
Find more on 低水準ファイル I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!