Graph columns where x value in a narrow range is below a threshold value.

Hello,
I was trying to figure out how to plot columns with a threshold value for a range of x[10:13] where any of those y values are < -200.
Sample data below of 2d matrix (rows 1:46 and columns are about 1:500,000].
-43 72 127 -28
1 42 51 -49
41 -54 -35 -73
46 -32 -102 -142
-18 -65 -145 -165
-69 -110 -157 -113
-67 -166 -174 12
-109 -202 -166 31
-189 -209 -199 -167
-265 -261 -337 -273
-206 -254 -318 -285
-136 -246 -294 -210
-239 -206 -211 -136
-240 -167 -268 -127
-209 -221 -271 -62
-193 -245 -223 -63
-267 -228 -178 -93
-284 -194 -137 -158
-246 -158 -153 -187
-183 -113 -147 -236
-158 -164 -219 -244
-152 -169 -200 -219
-95 -125 -151 -185
-176 -118 -123 -232
-173 -144 -91 -266
-139 -149 -111 -179
-79 -174 -131 -176
-52 -201 -141 -163
-120 -175 -121 -172
-110 -176 -147 -201
-140 -196 -154 -133
-155 -137 -69 -130
-159 -83 -88 -151
-172 -65 -71 -62
-88 30 -9 -126
-86 -68 -45 -111
-61 -78 9 -59
9 -30 57 35
-80 -11 3 30
-66 -28 1 50
-33 8 23 35
-56 35 29 18
-17 31 -9 -85
70 -63 -60 -130
77 -106 -48 -120
20 -91 -27 -74

2 commentaires

Explain more about data....what each column corresponds to?
Sure, each column is an action potential/event. They're overlayed on top of each other. X is a time scale over miliseconds, y is generally in mV. I'm trying to sort different spikes/clusters by selecting like in the case in the picture below: at x= -0.5, select all columns select all columns where the y value is greater than 0.015 mV.

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 17 Juil 2020
Modifié(e) : Cris LaPierre le 17 Juil 2020
This is not the way to group action potentials, especially if you want to try to group 500,000 of them. I'd recommend looking into a clustering algorithm. You first need to find a way to represent each action potential. You can use pca for this. You would then use the cluster number to idenitfy a particular set of action potentials.
Share your data, and I can probably give you an example.

6 commentaires

Gotcha, I'll hunt for some data I can share. I also looked through some of what you posted here, and it's a lot more clear, so thanks for the direction.
Here's some sample code. This will identify 2 action potential groups from the dataset apData
% Create a time vector.
t = linspace(-1,1,size(apData,2));
% Compute principal comonents
[coeff, newAP] = pca(apData);
% Visualize raw data
plot(t,apData(1:200,:))
xlabel('Time (ms)')
ylabel('Voltage (uv)')
% Cluster the scores
[IDX,C,~,dist] = kmeans(newAP,3,"Replicates",5);
% View clustered data in 2D
figure()
% C1
plot(newAP(IDX == 1,1),newAP(IDX == 1,2),'.r','MarkerSize',1)
hold on
plot(C(1,1),C(1,2),'.k','Markersize',15)
% C2
plot(newAP(IDX == 2,1),newAP(IDX == 2,2)'.b','MarkerSize',1)
plot(C(2,1),C(2,2),'.k','Markersize',15)
hold off
axis equal
% Only select points close to cluster centroid
% compute StD in each cluster (distance from each point to the cluster center)
std_c1 = std(dist(IDX == 1,1));
std_c2 = std(dist(IDX == 2,2));
% find points within 1 std
ind_c1 = find(dist(:,1) <= std_c1 & IDX == 1);
ind_c2 = find(dist(:,2) <= std_c2 & IDX == 2);
% Plot grouped waveforms (2 clusters)
figure()
plot(t,apDatal(ind_c1(1:200),:),'b')
hold on
plot(t,apDATA(ind_c2(1:200),:),'r')
hold off
xlabel('Time (ms)')
ylabel('Voltage (uv)')
To be clear, this code would need to be modified to find more than 2 groups. Do not attempt to plot all the data as you won't be able to see anything. Also note that kmeans assigns cluster numbers randomly, so the colors may switch from one run to the next. That's fine.
Fantastic! Thanks so much for the help/guidance. Running through a bit of this right now to get a feel for it.
% Compute principal comonents
[coeff, newAP] = pca(apData);
% Visualize raw data
plot(t,apData(1:200,:))
xlabel('Time (ms)')
ylabel('Voltage (uv)')
So, with computing pca I get an error type:
Error using pca (line 164)
The value of X must be a floating point array.
Would converting the waveforms to type single work for this?
No, the input can be single or double, so I don't imagine this would change anything. Check the datatype of your array in the Workspace. Is it something else?
Another thing to check is the values in your array. There is a possibility some values may not have gotten recorded. Inspect your data for any missing or erroneous recordings. You might try using ismissing, isempty, and isnan to check.
Thanks,
It did end up being a rogue missing value.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by