Only last data in struct? How to load all data in struct?
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 13 Dec 2020
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 Comments
Image Analyst
on 13 Dec 2020
If it worked for you and your problem is now solved, then you can thank us answerers by "Accepting the answer". Thanks in advance.
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!