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

2 次查看(过去 30 天)
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 个评论
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