load multiple .mat files
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
hi everyone,
I have a question.
I am analysing some data which have multiple subjects. Information about every subject is stored in the MATLAB structure (.mat file)
For Example:
U1_Acc_TimeD_FreqD_FDay.mat
U2_Acc_TimeD_FreqD_FDay.mat
U1_Acc_TimeD_FreqD_FDay.mat
and so on...
I would like to create for loop which in every iteration load new data_number.mat file.
I'd like in every iteration to load next .mat file? Particularly, I don't know how to address number part of filename using load function.
I tried this code and seems it's overwritten the data!
clear;
for nc = 1:36
load(['U', num2str(nc,'%2d'), '_Acc_TimeD_FreqD_FDay.mat']);
end
Thank you
채택된 답변
Walter Roberson
2016년 12월 28일
load(['U_', num2str(nc,'%02d'), 'Acc_TimeD_FreqD_FDay.mat']);
or
load( sprintf('U_%02dAcc_TimeD_FreqD_FDay.mat', nc) );
댓글 수: 10
dear Walter Roberson, thank you very much. Just a small correction, if you don't mind because your code gives a simple error due to the file name
for nc = 1:36
load(['U', num2str(nc,'%2d'), '_Acc_TimeD_FreqD_FDay.mat']);
end
Again really your answer was so useful. thank you mate.
neamah al-naffakh
2016년 12월 28일
편집: neamah al-naffakh
2016년 12월 28일
dear Walter Roberson, this code is uploading only the one mat file!! could you help me please? seems is data is overwritten!
Your question did not ask for the data to be stored separately.
for nc = 1 : 36
data{nc} = load( sprintf('U_%02dAcc_TimeD_FreqD_FDay.mat', nc) );
end
This will give you a cell array of structures, with each structure containing one field for each variable that is stored in the .mat file.
If you already know the name of the variable you want to extract, then,
for nc = 1 : 36
file_data = load( sprintf('U_%02dAcc_TimeD_FreqD_FDay.mat', nc) );
data{nc} = file_data.NameOfVariableGoesHere;
end
This code does not assume that the size or data type of the stored information is all the same. If you know that it is vectors that are consistent length, then you could use
for nc = 1 : 36
file_data = load( sprintf('U_%02dAcc_TimeD_FreqD_FDay.mat', nc) );
data(:,nc) = file_data.NameOfVariableGoesHere;
end
after which the data would appear as columns, one column for each file.
neamah al-naffakh
2016년 12월 28일
편집: neamah al-naffakh
2016년 12월 28일
Dear Walter Roberson,
I really appreciate your kind help.
I am trying to access each Struct inside the cell (data) and extract specific rows and columns.
I have written this code but it stores the data of the last Struct only!
clear;
for nc = 1 : 36
data{nc} = load( sprintf('U%02d_Acc_TimeD_FreqD_FDay.mat', nc) );
end
for j=size(data,2)
Feat_Vec1=(data{j}.Acc_TD_Feat_Vec(2:36,1:126));
end
could you help me with this please?
for j = 1 : size(data,2)
Feat_Vec1(:,:,j) = data{j}.Acc_TD_Feat_Vec(2:36,1:126);
end
This would create a 35 x 126 x 36 array
neamah al-naffakh
2016년 12월 28일
편집: neamah al-naffakh
2016년 12월 28일
thank you so much, but actually, it doesn't give me the correct output!
*it converts the values of each struct into 0 :(*
please see

when I use this code, I get what I want but only for the last struct (36) in the cell data
clear;
for nc = 1 : 36
data{nc} = load( sprintf('U%02d_Acc_TimeD_FreqD_FDay.mat', nc) );
end
for j=size(data,2)
Feat_Vec1{j} = data{j}.Acc_TD_Feat_Vec(2:36,1:126);
end
please have a look on here !!

neamah al-naffakh
2016년 12월 28일
편집: neamah al-naffakh
2016년 12월 28일
I have solved it but it's really weird !!
clear;
for nc = 1 : 36
data{nc} = load( sprintf('U%02d_Acc_TimeD_FreqD_FDay.mat', nc) );
end
for j=1:36 *% instead of for j=size(data,2)*
Feat_Vec1{j} = data{j}.Acc_TD_Feat_Vec(2:36,1:126);
end
Notice I had suggested
for j = 1 : size(data,2)
rather than
for j = size(data,2)
the second of those does only size(data,2)
neamah al-naffakh
2016년 12월 30일
편집: neamah al-naffakh
2016년 12월 30일
dear Walter Roberson, many thanks for your help. I really appreciate it.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
