Skipping steps while loading data? Debugging tool used

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

Risposte (2)

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 Commenti

I don't know enough about the contents of your files to propose a solution for not overwriting EMGHRmaartendata. A good start would be to watch the video I shared in my first post.
I think you are misusing addpath. This adds a folder to your MATLAB path. If does nothing to your startpath. Notice that none of your paths contain "Assignment_V2" in them. I'd simplify things.
Datapath ='E:\MATLAB\1EXAMENOPDRACHT\Assignment_V2\Data';
Then take note of the hint I provided in my original reply about using the results of the dir command when loading data.
Note in your workspace that pathwayEMG_HR is empty (0x1). This means nothing was found that matched your filter. Because it is empty, the second for loop never runs. Therefore, EMGHRmaartendata never gets created.
>> startpath ='E:\MATLAB\1EXAMENOPDRACHT';
Datapath = fullfile(startpath,'Data');
for i = [3 5 7 9 11 13 14 15 16 17]
dataFolder = fullfile(Datapath,"TD"+i);
filePattern = fullfile(dataFolder, '**/EMG/HR*.mot')
end
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD3\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD5\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD7\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD9\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD11\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD13\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD14\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD15\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD16\**\EMG\HR*.mot"
filePattern =
"E:\MATLAB\1EXAMENOPDRACHT\Data\TD17\**\EMG\HR*.mot"
>>
I'm guessing that is NOT the sequence of paths you're actually looking for but that the wildcard is not where intended.
But, we don't know the actual directory structure so that's a guess.
Also note the comments above...and that the empty dir() result is probably owing to the above--you're not looking at the location you think you are.
I am having another issue now .. the for loop for i and k is not working
error: Dot indexing is not supported for variables of this type.
Error in MCDO (line 88)
time = AEMGstructHR(i,k).data.data(:,1); %elke file invullen, kolom 1 = time
for i = [3 5 7 9 11 12 14 15 16 17]
for k = 1:length(pathwayEMG_HR)
for s = 2:6 %kijken welke spier in welke kolom door data.colheaders in command window te typen = RF 2e kolom, VL 3e, VM 4e, BF 5e, ST 5e
time = AEMGstructHR(i,k).data.data(:,1); %elke file invullen, kolom 1 = time
Spier = AEMGstructHR(i,k).data.data(:,s); % elke file invullen, kolom 2:6 = Rectus Femoris t/m Semitendinosus
fs = 900; %selected frequency, want laagste frequentie in tabel
N = 2; %selected order
fc1 = 5; %eerste cut off frequentie
fc2 = 200;%tweede cut off frequentie
[b,a] = butter(N,[fc1/(fs/2) fc2/(fs/2)]);
filtSpier = filtfilt(b,a,Spier);
% plot voorbeeld TD11 HR1 RF
if i == 11 && k == 1 && s == 2 %TD11 && HR1 && RectusFemoris
figure()
plot(time, filtSpier);
xlabel('time [s]');
ylabel('EMG [(micro)volt?????????]');
title ('EMG TD11 HR1 Rectus Femoris')
end
end
end
end
for i = [3 5 7 9 11 12 14 15 16 17]
for k = 1:length(pathwayEMG_MR)
for s = 2:6 %kijken welke spier in welke kolom door data.colheaders in command window te typen = RF 2e kolom, VL 3e, VM 4e, BF 5e, ST 5e
time = AEMGstructMR(i, k).data.data(:,1); %elke file invullen, kolom 1 = time
Spier = AEMGstructMR(i, k).data.data(:,s); % elke file invullen, kolom 2:6 = Rectus Femoris t/m Semitendinosus
fs = 900; %selected frequency, want laagste frequentie in tabel
N = 2; %selected order
fc1 = 5; %eerste cut off frequentie
fc2 = 200;%tweede cut off frequentie
[b,a] = butter(N,[fc1/(fs/2) fc2/(fs/2)]);
filtSpier = filtfilt(b,a,Spier);
% plot voorbeeld TD9 MR4 BF
if i == 9 && k == 4 && s == 5 %TD9 && MR4 && BicepsFemoris
figure()
plot(time, filtSpier);
xlabel('time [s]');
ylabel('EMG [(micro)volt?????????]');
title ('EMG TD11 HR1 Rectus Femoris')
end
end
end
end
error: Dot indexing is not supported for variables of this type.
Error in MCDO (line 88)
time = AEMGstructHR(i,k).data.data(:,1); %elke file invullen, kolom 1 = time
Well, we have nothing to go on...your data after you read it isn't at least a doubly-deep structure but we have no way to know anything about what it might be since you've not shared anything about it except to complain it doesn't work.
If you expect useful help, do your part and show us enough information to be able to do something with it. Attaching a file would be simplest by far, showing us what
whos AEMGStructHR
whos AEMGStructHR(i,k)
returns would at least help altho not necessarily sufficient.
Sorry for the lack of information! I put the files in attachment. But can you explain what the error of dot indexing means?
Let me know if there is any more information i have to provide, thanks!
First question is still what do your data files look like? We can't recommend a strategy until we know that.
  • What is the size of the imported data?
  • Does each file contain the same number of points?
  • Is the imported data all of the same data type?
Dot indexing refers to the syntax "varName.FieldName". From a variables standpoint, this is used to extract data from structures and tables. For example, the result of dir is a mx1 structure containing 6 fields:
  • name
  • folder
  • date
  • bytes
  • isdir
  • datenum
You capture the result of this command in the variable pathwayEMG_HR. You need the folder and name to load the file. I used dot indexing to construct the importdata command:
EMGHRmaartendata = importdata(fullfile(pathwayEMG_HR(k).folder,pathwayEMG_HR(k).name));
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!
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.

Accedi per commentare.

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

Categorie

Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange

Richiesto:

il 15 Dic 2020

Commentato:

il 16 Dic 2020

Community Treasure Hunt

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

Start Hunting!

Translated by