Skipping steps while loading data? Debugging tool used

1 view (last 30 days)
Script does not execute the steps after for i loop? What could be the fault? Thanks!
startpath ='E:\MATLAB\1EXAMENOPDRACHT';
addpath([startpath,'\Assignment_V2']);
Datapath = [startpath '/Data'];
for i = [3 5 7 9 11 13 14 15 16 17]
dataFolder = [Datapath '/TD' num2str(i)];
filePattern = fullfile(dataFolder, '**/EMG/HR*.mot'); %naam van de map een bestandsnaam geven
pathwayEMG_HR = dir(filePattern);
for k = 1:length(pathwayEMG_HR)
EMGHRmaartendata = importdata([dataFolder '/EMG/HR_' num2str(k) '_emg.mot']); % om matlab file van subject te loaden
end
end

Answers (2)

Cris LaPierre
Cris LaPierre on 15 Dec 2020
Is it skipping it or just not giving you the expected result? Have you checked that the path and file name for your importdata code is correct?
Are there any error messages? If so, please share the entire error message (all the red text).
If you go through the trouble of creating pathwayEMG_HR, why not use it to import your data?
EMGHRmaartendata = importdata(fullfile(pathwayEMG_HR(k).folder,pathwayEMG_HR(k).name));
Note that you are overwriting EMGHRmaartendata every time. You probably want to come up with some strategy to keep all of it. For an example, see this video.
  9 Comments
Alexa Z
Alexa Z on 16 Dec 2020
Yes, we are now running for loops for exercises. For example plotting subplots but we get each time the same figure plotted. So we think it is not running for each subject or each file of a subject ..
  • What is the size of the imported data? it is a 1x1 struct, 8410x6 double (data) --> if we click on EMGHRmaartendata we only see the results for one subject & for one file (some subjects could have more files than others)
  • Does each file contain the same number of points? yes, it is EMG measured: 8410x6 --> but we were not able to check for all files/subjects --> with the debugging tool, it flipped to the next k and to the next i --> but nothing changed in the EMGHRmaartendata
  • Is the imported data all of the same data type? yes, all mot files
How can we make sure that we are loading the data for each file and subject? Or would there be something missing in our next exercises, and the problem is not with the loading?
Thanks for checking!
Cris LaPierre
Cris LaPierre on 16 Dec 2020
The issue is with the "data.data()" part. You are adding an extra field name that doesn't exist.
EventMRdata = rand(4,5);
AEMGstructMR(1,4).data = EventMRdata;
AEMGstructMR(1,4).data(:,1)
ans = 4×1
0.1584 0.0768 0.1058 0.1184
AEMGstructMR(1,4).data.data(:,1)
Dot indexing is not supported for variables of this type.
Sounds like this is for a class. Do you have an instructor or TA who could look at what you are doing? They'll have the proper context to answer the questions you are asking.

Sign in to comment.


Alexa Z
Alexa Z on 15 Dec 2020
I fixed it thanks!!!
% load EMG HR
startpath ='E:\MATLAB\1EXAMENOPDRACHT\Assignment_V2';
addpath([startpath,'\Assignment_V2']);
Datapath = [startpath '\Data'];
for i = [3 5 7 9 11 13 14 15 16 17]
dataFolder = [Datapath '\TD' num2str(i)];
dataFile = fullfile(dataFolder, '\EMG\HR*.mot'); %naam van de map een bestandsnaam geven
pathwayEMG_HR = dir(dataFile);
for k = 1:length(pathwayEMG_HR)
%EMGHRmaartendata = importdata([dataFolder '\EMG\HR_' num2str(k) '_emg.mot']);
% om matlab file van subject te loaden
EMGHRmaartendata = importdata(fullfile(pathwayEMG_HR(k).folder,pathwayEMG_HR(k).name));
EMGstructHR(i,k).data = EMGHRmaartendata;
end
end

Categories

Find more on Debugging and Analysis 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!