Reading data from a file name

3 ビュー (過去 30 日間)
Steven
Steven 2012 年 2 月 5 日
Hello MatLab Community,
I am loading csv files and am posed with a unique problem. The data file's name contains pertinent information that I need to extract. For example, one such file name is 'SUNY_072054055.csv' and I would like to extract 07205 from the file name as 072.05 and extract 4055 as 40.55. Both of these values I will set a variables to be used later on in future analysis.
I have already loaded the file names into matlab as strings. For example, files(1).name = 'SUNY_072054055.csv'
Any help would be appreciated.
Thanks to all,
Steven

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 5 日
find() the location of the '_' and of the '.' . Extract the string between those positions. Take the first 5 characters, str2double() it, and divide by 100. Take the last 4 characters, str2double() it, and divide by 100.
  3 件のコメント
Image Analyst
Image Analyst 2012 年 2 月 5 日
Use strfind() to find those characters. Then fn(index1:index2) to extract a string from fn in between index1 and index2 inclusive.
Steven
Steven 2012 年 2 月 8 日
Walter, Image Analyst, thank you very much for your help. Your guiding light showed me the way :-)
All the best,
Steven

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by