How to export CSV file from folder to MATLAB work space with their parent folder serial number ?

1 回表示 (過去 30 日間)
Hari
Hari 2015 年 8 月 3 日
回答済み: Prateekshya 2024 年 9 月 2 日
I have i csv file numbered 1 to 100 serially. I need to process that file in sequence. When i am reading the file through "dir" command the structure is coming like 1,10,100,2..... but i need it as 1,2,3....
Please provide kind support.
Thanks
Hari

回答 (1 件)

Prateekshya
Prateekshya 2024 年 9 月 2 日
Hello Hari,
While using dir command, the default sorting order is lexicographical order which results in the order 1, 10, 100, ... . To sort it according to the numeric values, you need to extract the file names and do it manally. You can use str2double function for this purpose. Please find the documentation to the same: https://www.mathworks.com/help/matlab/ref/str2double.html.
Using this function you can convert the file names to numeric values and then apply sorting on those values.
I hope this helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by