필터 지우기
필터 지우기

Only last data in struct? How to load all data in struct?

조회 수: 7 (최근 30일)
Alexa Z
Alexa Z 2020년 12월 13일
댓글: Image Analyst 2020년 12월 13일
Hello.
How can you avoid overwriting data in struct? Data struct now only provides data of last file in EMG. Normally there are 6 files of EMG. How can I put all of them in a struct?
Thanks.
%% load EMG data
myFolder = 'E:\**\Assignment_V3\Data'
if ~isfolder(myFolder)
errormessage = sprintf('Error: The folder does not exist');
myFolder = uigetdir();
if myFolder == 0
return;
end
end
filePattern = fullfile(myFolder, '**/EMG/*.mot');
pathway = dir(filePattern);
for k = 1:length(pathway)
EMGfile = pathway(k).name;
EMGcorrectfile = fullfile(pathway(k).folder, EMGfile);
fprintf(1, 'Now reading %s\n', EMGcorrectfile);
EMGdata = importdata(EMGcorrectfile);
end

답변 (1개)

Image Analyst
Image Analyst 2020년 12월 13일
Attach 2 different .mot files so we can run your code.
In the meantime, try this untested code:
% Load EMG data
myFolder = 'E:\**\Assignment_V3\Data'
if ~isfolder(myFolder)
errormessage = sprintf('Error: The folder does not exist');
myFolder = uigetdir();
if myFolder == 0
return;
end
end
filePattern = fullfile(myFolder, '**/EMG/*.mot');
pathway = dir(filePattern);
for k = 1:length(pathway)
EMGfile = pathway(k).name;
EMGcorrectfile = fullfile(pathway(k).folder, EMGfile);
fprintf(1, 'Now reading %s\n', EMGcorrectfile);
EMGdata = importdata(EMGcorrectfile);
EMGstruct(k).data = EMGdata; % Add a structure to the structure array.
end
  댓글 수: 2
Alexa Z
Alexa Z 2020년 12월 13일
Thanks!!
Image Analyst
Image Analyst 2020년 12월 13일
If it worked for you and your problem is now solved, then you can thank us answerers by "Accepting the answer". Thanks in advance.

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by