Skipping steps while loading data? Debugging tool used
Mostra commenti meno recenti
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)
Cris LaPierre
il 15 Dic 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 Commenti
Cris LaPierre
il 15 Dic 2020
Modificato: Cris LaPierre
il 15 Dic 2020
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.
dpb
il 15 Dic 2020
>> 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.
dpb
il 15 Dic 2020
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.
Alexa Z
il 16 Dic 2020
Alexa Z
il 16 Dic 2020
Cris LaPierre
il 16 Dic 2020
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));
Alexa Z
il 16 Dic 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)
AEMGstructMR(1,4).data.data(:,1)
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.
Alexa Z
il 15 Dic 2020
Categorie
Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!