Graph columns where x value in a narrow range is below a threshold value.
Show older comments
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 Comments
KSSV
on 17 Jul 2020
Explain more about data....what each column corresponds to?
clayton hutton
on 17 Jul 2020
Answers (1)
Cris LaPierre
on 17 Jul 2020
Edited: Cris LaPierre
on 17 Jul 2020
0 votes
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 Comments
clayton hutton
on 17 Jul 2020
Cris LaPierre
on 17 Jul 2020
Edited: Cris LaPierre
on 18 Jul 2020
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.
clayton hutton
on 17 Jul 2020
clayton hutton
on 17 Jul 2020
Edited: Cris LaPierre
on 18 Jul 2020
Cris LaPierre
on 18 Jul 2020
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?
clayton hutton
on 19 Jul 2020
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!