MATLAB EEG signal processing - Channel location file - matlab

I'm trying the EEGLAB and FASTER plugins for MATLAB in order to do some processing for my EEG data, When trying to load the data file, I'm asked to choose the "channel location file", but I don't have that with my data, I was wondering if I can create it myself? And if so, How? I know that each channel in my data corresponds to a specific electrode, how can I write that in the location file? Thank you

You can do it by file or by code.
By file (I did not test it so it may not work):
create a text file with electrode names - one electrode per line, the order should be the same as in your file. Load the file through edit -> channel locations --> read locations (left bottom corner of the gui). Choose your text file and then use "look up locs" button to get corresponding locations on BESA or MNI head model.
By code and gui (should work well):
Create a variable with electrode names (have to be correct names in correct order):
elec_names = {'Cz', 'O1', 'O2', 'Fp1', 'Fp2'};
[EEG.chanlocs.labels] = deal(elec_names{:});
eeglab redraw;
Then use the edit -> channel locations --> look up locs option. Later you can type eegh in command window to get the command that would work on your computer.

This sounds like you are not really aware of how EEGLAB works.
From the EEGLAB wiki page on the topic of "Channel Location"
To plot EEG scalp maps in either 2-D or 3-D format, or to estimate
source locations for data components, an EEGLAB dataset must contain
information about the locations of the recording electrodes.
KEY STEP 5: Load the channel locations.
To load or edit channel location information contained in a dataset, select Edit > Channel locations.

Related

Why am I getting "Unable to read file 'topo60c'. No such file or directory" error in Matlab?

Many of Matlab's Mapping toolbox examples require "topo60c" world map data. Here's an example
load topo60c
axesm hatano
meshm(topo60c,topo60cR)
zlimits = [min(topo60c(:)) max(topo60c(:))];
demcmap(zlimits)
colorbar
However, when I run the above script, Matlab displays a file not found error for "topo60c". Does anyone know why I'm getting this error? I have the Mapping toolbox installed, and it works with other Mapping sample code that doesn't reference that file.
In the acknowledgements section of the mapping toolbox docs there is a note about example data sources:
https://uk.mathworks.com/help/map/dedication-and-acknowledgment.html
Except where noted, the information contained in example and sample data files (found in matlabroot/examples/map/data and matlabroot/toolbox/map/mapdata) is derived from publicly available digital data sets. These data files are provided as a convenience to Mapping Toolbox™ users. MathWorks® makes no claims that any of this data is free of defects or errors, or that the representations of geographic features or names are up to date or authoritative.
You can open these folders from MATLAB (on Windows) using
winopen( fullfile( matlabroot, 'examples/map/data' ) )
winopen( fullfile( matlabroot, 'toolbox/map/mapdata' ) )
Or simply use the fullfile commands above to identify the paths and navigate there yourself.
I can see (MATLAB R2020b) the topo60c file within the first of these folders, which isn't on your path by default because it's within "examples" and not a toolbox directory:
So you could either:
Add this folder to your path so that MATLAB can see the file: addpath(fullfile(matlabroot,'examples/map/data'));
Reference the full file path to the data when running examples: load(fullfile(matlabroot,'examples/map/data/topo60c.mat'));
I would prefer option 2 to avoid changing the path.
Additionally, there is another note in the Raster Geodata section of the docs which details what that dataset should contain
https://uk.mathworks.com/help/map/raster-geodata.html
When raster geodata consists of surface elevations, the map can also be referred to as a digital elevation model/matrix (DEM), and its display is a topographical map. The DEM is one of the most common forms of digital terrain model (DTM), which can also be represented as contour lines, triangulated elevation points, quadtrees, octree, or otherwise.
The topo60c MAT-file, which contains global terrain data, is an example of a DEM. In this 180-by-360 matrix, each row represents one degree of latitude, and each column represents one degree of longitude. Each element of this matrix is the average elevation, in meters, for the one-degree-by-one-degree region of the Earth to which its row and column correspond.
Given that it's generated from publically available data anyway (ref the first docs quote) and you now know what data it represents (ref the 2nd docs quote), you could replicate some replacement data if really needed.

how to edit an eeg data file?

i have a file : 30_19.1.20.eeg , which contains eeg data , i want to split this data into two halves . so first i imported the data file to matlab using the following :
i imported a 30_19.1.vhdr file into eeglab using : file->import data -> using eeg functions and plugins -> from brain vis. Rec.vhdr or ahdr file
after that i received in the matlab workplace the following :
enter image description here
so i want to open the data file so i pressed the EEG struct ,
this is what it contains :
enter image description here
and this struct contains a filed called data , when i open it i have a matrix that contains all of the data
basically i want to split this data into half .
how can i do such a thing ?
i tried to change this struct but i always get the following error :
enter image description here
Structures are variables which have "sub-variables" called properties inside them, a bit like directory / sub-directory structures.
Assuming the data in your eeg variable is called data, you can do the following to load the data into a new variable: m = eeg.data. If you want to load half of that data, assuming the half is in terms of numbers of rows, then you could write:
m = eeg.data(1:floor(size(eeg.data,1)/2),:);
You may want to "select data" from the continuous EEG dataset file. There are 2 options:
time range in seconds
point range (one-sample precision)
You have to apply this procedure twice (lower range, higher range) to get the 2 separate files.
After doing so, you can type EEG.history in the command window to get the Matlab code that has been executed.

Example data sets in Matlab

There are several example data sets in Matlab, for example wind and mri. If you execute the command load wind you will load the data in the data set wind. Some are included in toolboxes and some appear to be included in standard Matlab. These example data sets are valuable as test data when developing algorithms.
Where can one find a list of all such data sets included in Matlab?
You can enter demo in matlab to get a list. The wind table is part of Example — Stream Line Plots of Vector Data, etc.
For the tables on your computer, have a look at:
C:\Program Files\MATLAB\R2007b\toolbox\matlab\demos
The example data is located in .mat files in ../toolbox/matlab/demos.
The following data is available in MATLAB 2014a:
% in matlab run:
> H=what('demos')
> display(H.mat)
You can also use your favorite Linux console:
/usr/local/MATLAB/R2014a/toolbox/matlab/demos$ ls *.mat -1 | sed -e "s/.mat//g"
This is my list for readers who can not try it on their machine while reading this answer:
accidents
airfoil
cape
census
clown
detail
dmbanner
durer
earth
flujet
gatlin
gatlin2
integersignal
logo
mandrill
membrane
mri
patients
penny
quake
seamount
spine
stocks
tetmesh
topo
topography
trimesh2d
trimesh3d
truss
usapolygon
usborder
vibesdat
west0479
wind
xpmndrll
While the command demo in MATLAB 2018b will start a help browser with some demos:
You can find a list of all available dataset and their description in the following link :
https://www.mathworks.com/help/stats/sample-data-sets.html

Pop-up windows asking the user for input/save his work (MATLAB)

I am writing a program and I need some help. It starts by asking this question:
A = questdlg('What would you like to do?','Artificial Neural Network',...
'Train','Test','Exit','Exit');
Then depending what the use chooses it asks certain questions and do certain things
`if strcmp (A,'Train')
B = questdlg ('Would you like to create a new network or add to the already trained data?',...
'!','Create','Add','Exit','Exit');
if strcmp (B, 'Create')
if strcmp (B, 'Create')
%add as many text file as he wants to - need to figure out how I
%can extract the data from them though
[fname,dirpath]=uigetfile ('*.txt','Select a txt file','MultiSelect',...
'on');
elseif strcmp(B,'Add')
%choose what type is it
D = listdlg('PromptString','What colour is it?',...
'SelectionMode','single', 'ListString',...
{'Strawberry','Orange',...
'Chocolate','Banana','Rose'}, 'Name','Select Ice Cream',...
'ListSize',[230 130]);
%and then whatever choise he chooses it will feed it to the main
%function. For example if he chooses Orange then it will go the
%second part of the training, if it chooses Rose and the fifth
%one and so on.
else strcmp(B,'Exit')
disp('Exit')
end
So the thing I want help with is:
How can the user when he imports the txt files in Matlab use them in order to run the program? and
How can the user add more choices at the listdlg and when it will choose a choice then automatically it will go to the corresponding step of the code?
Any help would be appreciated!
Thanks!! :)
PS: Sorry for the long post!
with uigetfile etc. you only get the filename and path. But to get the data you have to load the file:
For mat-files use:
TMW: load mat-files
For other files use:
TMW: load data from file
To open a file in MATLAB, you can use uigetfile. To save a file, you can use uiputfile. This will open up standard file dialog boxex for opening and saving files. The result would be a cell array, and then use textscan to read the data from the individual files.
You should switch-case. On selecting one of the choices, you can train the neural network accordingly. The training preferably should be written in separate m files or different subfunctions for readability.

Automatic file opening in MATLAB

I'm running a program on magnetometry. I have a file which contains over 10 text files, each containing the data (amplitude vs frequency) at a precise magnetic field value.
My program then reads each of those files, plotting the data, making a fit over those and then I use this fit to find the magnetic field depending on the distance of the frequency between 2 amplitude peaks (that's just theory, it's not necessary to understand this part).
All I want is some lines of code that would open all the files in the specified directory and let me use the datas
(i.e. data = importdata(filenames{i},delimiterIn,headerlinesIn);)
And later on I have a line that ask the user which data file he wants to open, and it gives back the magnetic field value.
So I need to use two folders : the one containing the data to create my fit and equations.
And the one containing whatever data file the user wants to open to find the magnetic field applied while getting data.
It isn't clear from the question if you want the user to do this interactively or not, so I assumed you do.
To select a folder you can use uigetdir , for example:
d = uigetdir('C:\');
will displays directories on the C: drive to select from, etc...
Similarly, to select all the files in that folder you can use dir. For example, if you want to pick out all the TXT files in a folder that the user selects:
d = uigetdir(pwd, 'Select a folder');
files = dir(fullfile(d, '*.txt'));