필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Need to conduct analysis across four .mat files at once - how do I load multiple .mat files?

조회 수: 1 (최근 30일)
I am trying to create a function that utilizes a struct containing four different sets of data so that I can analyze data across all four sets. What do I need to do? i.e. I have dataset1.mat, dataset2.mat, dataset3.mat, and dataset4.mat and I want to track data across all 4 of these.
  댓글 수: 2
Stephen23
Stephen23 2020년 8월 16일
편집: Stephen23 2020년 8월 16일
Follow the examples in the documentation:
It is more reliable to load into an output variable (which is a scalar structure), e.g.:
S = load(...);
Bin John
Bin John 2020년 8월 16일
Hi, thanks for your response!
This is the function I have built, but when I run LoadFiles in my command window, I get the error, "Conversion to double from struct is not possible." What am I doing wrong?
function LoadFiles
filenames = {'sessionData1.mat','sessionData2.mat','sessionData3.mat', 'sessionData4.mat'};
s = [1 4];
for i = 1:numel(filenames)
s(i) = load(filenames{1,i});
end
end

답변 (1개)

Antonio Ciociola
Antonio Ciociola 2020년 8월 16일
The problem seems to be related to this instruction:
s = [1 4];
But then you're loading the mat files in this way:
s(i) = load(filenames{1,i});
So,you're trying to put a structure into an array of double.
Try to change the code by removing the wrong line of code (s=[1 4])
  댓글 수: 2
Bin John
Bin John 2020년 8월 16일
When I do that, I get "Subscripted assignment between dissimilar structures."
Antonio Ciociola
Antonio Ciociola 2020년 8월 16일
편집: Antonio Ciociola 2020년 8월 16일
This happens because you have different mat files. Try with this line of code:
s{i} = load(filenames{1,i});

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by