Reputation: 59
I'm trying to read a .mat file and trying to plot the signal and its magnitude (half period). My code is
%Read EEG (.mat)
EEG_read = load('EEG.mat');
f_EEG = 100; %frequency
n3 = 0:1/100:pi;
subplot(2, 1, 1)
plot(EEG_read)
xlabel('t(s)') %signal
legend('EEG')
subplot(2, 1, 2)
plot(n3, abs(fft(EEG_ler))) %DFT
xlabel('f(Hz)')
legend('DFT EEG')
Thanks in advance.
Note: The .mat file is a part of a real EEG and it contains only one variabe 1x2000, struct type
Upvotes: 0
Views: 261
Reputation: 4757
.mat
DataIf you have saved a variable named EEG_read
in a MATLAB file there are two ways to access it. You have two ways of loading the .mat
. Option 1 is to load all the data/variables into a structure. Option 2 is to load all the data/variables directly into the workspace.
.mat
Loaded Structure:This method loads all the .mat
data into a structure in this case I called the structure Structure
. Within this structure, all the variables in the .mat
file can be accessed by .
indexing each member of this structure. Since there is only one variable in this structure called EEG_read
we can access this variable by calling Structure.EEG_read
.
Structure = load('EEG.mat');
subplot(2, 1, 1); plot(Structure.EEG_read);
.mat
and Directly into the WorkspaceThis method will load all the workspace variables within the .mat file
exactly as when they were saved. The variable names will remain the same as they were when saved.
load('EEG.mat');
subplot(2, 1, 1); plot(EEG_read);
Ran using MATLAB R2019b
Upvotes: 1