How to dissect a file path and keep extension Matlab

1 次查看(过去 30 天)
I have my file path in a string :
path = 'D:\Users\Documents\MATLAB\capella_to_matlab.txt'
How can i put only the extension in an other string (Not just for this file but for any file i put in path variable) for example :
extension = '.txt'
Thanks for helping !

采纳的回答

Stephen23
Stephen23 2019-4-15
编辑:Stephen23 2019-4-15
Do NOT use path as a variable name! This shadows the important inbuilt path function.
To get the file extension use fileparts:
>> P ='D:\Users\Documents\MATLAB\capella_to_matlab.txt';
>> [~,~,E] = fileparts(P)
E = '.txt'

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by