import file by specifying its location - without GUI
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, is there any function in "Matlab" that allows to specify file (.txt) location and import its data without using GUI?
Thanks in advance
2 件のコメント
Walter Roberson
2013 年 5 月 21 日
How much interactivity is expected? e.g., should the use be able to go up and down levels of directories and see the filenames in the directories, all done through text?
回答 (3 件)
Walter Roberson
2013 年 5 月 21 日
If you are processing text files, then they do not normally have variables, just data and headers. Are you expecting there to be column headers and expecting that MATLAB will synthesize variable names from the column headers?
Is the .txt file just a mix of comments ('%' at beginning of lines) and rectangular columns of data? If so then you can load() -ASCII the .txt file.
You might be able to use uiimport() to deduce the pattern associated with the text file.
If you know what the pattern of the text file is supposed to be then you are usually best off using textscan()
2 件のコメント
Iain
2013 年 5 月 21 日
No. You need to open a file to get a file ID (fid = fopen(filename,'r'); for reading), and once you're done with the file, you need to close it (fclose(fid)), and if you need to re-read, you'll either need to reopen it, or use fseek.
Iain
2013 年 5 月 21 日
Yes. You can use low level functions to read text files of any format, provided you tell matlab exactly what to do to read the data from the files: (fopen, fread, fclose.)
There are some functions that read lines from open files (eg. textscan)
There are some functions that read simply formatted files eg. dlmread, csvread, load.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!