How to import data from a specific folder in MATLAB

106 ビュー (過去 30 日間)
Sanka
Sanka 2013 年 2 月 25 日
Hi all,
I am trying to import a number of text files into my workspace so that I can do some data analysis and post-processing on them. The problem is these files are located in folders that are not in my current directory. I know I can change my directory or import them manually using the GUI but I would prefer to have some function that can import them immediately and that I can incorporate this function into my post-processing m-code.
I previously used something like this to import the files from the current directory:
clear all
files = dir('*.lvm');
for i=1:length(files);
eval(['load ' files(i).name ' R3F1T_']);
end
Maybe there is a way of modifying this simple code to allow me to import the same data from differnt folders?
Thanks in advance

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 25 日
load(filenames(1).name)

Image Analyst
Image Analyst 2013 年 2 月 25 日
filePattern = fullfile(yourFolder, '*.lvm');
files = dir(filePattern);
Then go read the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F for instructions and code examples on how to process files without using eval().
  1 件のコメント
Sanka
Sanka 2013 年 2 月 26 日
Thanks for the answer Image Analyst but still not working!
I tried implementing the code as following:
clear all;
filePattern=fullfile('C:','Users','Documents','Inlet Temp','*.lvm');
files=dir(filePattern);
for i=1:length(files);
eval(['load ' files(i).name ' R3F1T_']);
end
Keep getting an error stating:
??? Error using ==> load
Unable to read file R3F1T.lvm: No such file or directory.
Error in ==> test_load at 6
eval(['load ' files(i).name ' R3F1T_']);
Any more help/advice would be greatly appreciated. Seems like a small issue but is really bothering me!

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

カテゴリ

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