Plotting with data in .mat files

1 visualización (últimos 30 días)
Shamus Sim
Shamus Sim el 9 de Ag. de 2020
Editada: NA el 9 de Ag. de 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:
load('interictal_segment_255')
%Plotting time-series for ECG data
%sampling frequency
sf=399.0698
T=1/sf
Xplot=T:T:600
plot(Xplot,interictal_segment_255.data)
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 comentario
Mario Malic
Mario Malic el 9 de Ag. de 2020
Your Xplot is a vector with 239441 elements and needs to have the same number of columns as your data which is 239766.

Iniciar sesión para comentar.

Respuestas (1)

NA
NA el 9 de Ag. de 2020
Editada: NA el 9 de Ag. de 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;
figure;
plot(timeSeries, data);
Try this to load your files, you will likely have to adjust it based on your directory.
animalFolder = {...
'Dog_1'...
'Dog_2'...
'Dog_3'...
'Dog_4'...
'Dog_5'...
};
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
end

Categorías

Más información sobre ECG / EKG en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by