Anonymous
Anonymous

Reputation: 59

Matlab is not reading a .mat file

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

Answers (1)

MichaelTr7
MichaelTr7

Reputation: 4757

Methods of Loading and Accessing .mat Data

If 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.


Accessing Variables From .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.

Accessing From Structure

Structure = load('EEG.mat');
subplot(2, 1, 1); plot(Structure.EEG_read);

Loading all Variables from .mat and Directly into the Workspace

This 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.

Loading all Workspace Variables

load('EEG.mat');
subplot(2, 1, 1); plot(EEG_read);

Ran using MATLAB R2019b

Upvotes: 1

Related Questions