Filter löschen
Filter löschen

Plotting with data in .mat files

2 Ansichten (letzte 30 Tage)
Shamus Sim
Shamus Sim am 9 Aug. 2020
Bearbeitet: NA am 9 Aug. 2020
HI there,
I am trying to make a simple time-series plot. My Yvalues(Voltage) are arranged in these data.mat files that traverse horizontally and then down to the next row, row by row. You can see here. data is a 16x239766 double. (You can see the lowest Screenshot)
The code I have wrote is:
%Plotting time-series for ECG data
%sampling frequency
The error I have gotten is:
Error using plot
Vectors must be the same length.
Also, Im trying to create a for loop to read all my data here.(See first screenshot). They are divide into Dog_1 until Dog_5. They all have the same field with the struct,interictal_segment_255. I have tried to create a for loop for this but unsucessful. Im trying to plot the time series for a particular segment when I call for it. Eg: interictal_segment_255 and get the plotted time series for the whole segment.
  1 Kommentar
Mario Malic
Mario Malic am 9 Aug. 2020
Your Xplot is a vector with 239441 elements and needs to have the same number of columns as your data which is 239766.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

NA am 9 Aug. 2020
Bearbeitet: NA am 9 Aug. 2020
You are getting an error because the vectors are not the same size.
You have a 16 x 239766 matrix and you want to plot it against a 1 x 239441, which is not possible because 239766 > 239441.
From your code, one can deduce that you have collected data over 600s. However, based on your sampling rate (399.0698), this time is actually slightly greater than 600s i.e. 239766 / 399.0698 = 600.8122. Which suggests that you collected data over 600.8122s rather than 600s.
By running the code below you should be able to plot your ECG data without encountering any errors:
data = rand(16, 239766); %dummy data
sf = 399.0698; %sampling frequency (Hz), samples per second
T = 1/sf;
timeSeries = T:T:600.8122;
plot(timeSeries, data);
Try this to load your files, you will likely have to adjust it based on your directory.
animalFolder = {...
animalN = size(animalFolder, 1);
directory = 'C:\Users\USERS\Desktop\SHAMUS\Dr.Lan\'; %check this
ecgData = '\interictal_segment_255';
time = '\xxxxx'; %replace xxxxx with name of time-series file
for ii = 1:animalN
folder = [animalFolder{ii,1} '\'];
load([directory folder ecgData]); %loads ecg data for each animal
load([directory folder time]); %loads time series for each animal

Community Treasure Hunt

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

Start Hunting!

Translated by