필터 지우기
필터 지우기

Import multiple data files and assign to variables

조회 수: 7 (최근 30일)
Calabrese
Calabrese 2015년 7월 27일
편집: Stephen23 2019년 6월 25일
I would like to import multiple data files and assign their contents to a variable.
BurnIn_2ndary_20150527_1940.mat
BurnIn_2ndary_20150528_1500.mat
BurnIn_2ndary_20150528_2200.mat
BurnIn_2ndary_20150529_1500.mat
BurnIn_2ndary_20150530_1000.mat
BurnIn_2ndary_20150530_2200.mat
BurnIn_2ndary_20150531_1600.mat
Each file consists of a 7x4 matrix (called 'details') that consists of the mean, std, min, and max values for 7 different parameters determined by data from its original file.
I am continually adding files to the folder for each set of data I get daily sometimes twice a day. I need to be able to import all files and assign them to different variables that could range to infinity (because I am continuously adding files).
I tried this
dir *2ndary*.mat
files = dir('*.mat');
for i=1:length(files)
eval(['load ' files(i).name]);
end
But I still don't know how to assign each matrix to a new variable for further use. I am worried that maybe because each matrix is called 'details' in each file from previous code might cause an issue

채택된 답변

Stephen23
Stephen23 2015년 7월 27일
편집: Stephen23 2019년 6월 25일
You should load the files into a variable, such as into a cell array:
C{k} = load(...);
or into a non-scalar structure, which would be versatile and efficient:
S(k) = load(...);
Note that you can also select the variables to load:
S(k) = load(...,'varname');
Avoid eval for trivial code like that:
  댓글 수: 2
Calabrese
Calabrese 2015년 7월 27일
Thank you for the tip on eval. Once I bring these files in I plan to create 7 different plots, one for each parameter. Each parameter plot will have the mean, std, min and max values for the corresponding day for which the data was taken over a continuing period of time.
What would be the best way to load in the data, in your opinion, to process what I need to do with it? Please provide an example if you can
I plan to load in the files and assign the same row on each file to one of the 1 of the 7 different parameters (which will be a matrix) that can continually grow.
Stephen23
Stephen23 2015년 7월 28일
편집: Stephen23 2015년 7월 28일
Load the data into a non-scalar structure, as I explained at the beginning of my answer. And read the link to know how to access the data inside of it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by