Borrar filtros
Borrar filtros

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

7 visualizaciones (últimos 30 días)
Alexa Z
Alexa Z el 13 de Dic. de 2020
Comentada: Image Analyst el 13 de Dic. de 2020
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

Respuestas (1)

Image Analyst
Image Analyst el 13 de Dic. de 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 comentarios
Image Analyst
Image Analyst el 13 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by