MATLAB: How to tell Matlab to Label the point where the subplots are equal

plotssubplots labeling

I'm trying to write a For loop for when KE (Subplot #1) is equal to PE (Subplot #2) and label it as an asterisk. Below is part of my main script and attached is a picture of the graph.
for n = 1:7
figure(2);
KE{n} = 0.5*m*(U{n}.^2 + V{n}.^2 + W{n}.^2 );
PE{n} = m*g*Z{n} ;
hold on
subplot(2,1,1);
plot(T{n},KE{n},color(n));
subplot(2,1,2);
plot(T{n},PE{n},color(n))
My attempt. I tried setting a For Loop for each line, such that when KE = PE, Matlab wouldd label the point as an asterick for both plots.
for n = 1:7
if KE{n}==PE{n}
subplot(2,1,1)
plot(KE{n}==PE{n},['*' color(n)]);
hold on
subplot(2,1,2)
plot(PE{n}==KE{n},['*' color(n)]);
end

Best Answer

Why are you using a cell array? It looks like you're better off with a numeric array and then you also wouldn't need a loop in that case. To calculate KE and PE, it's simply,
%dummy data
U = rand(10,7);
V = rand(10,7);
W = rand(10,7);
Z = rand(10,7);
%calculate KE and PE,
KE = 0.5*m*(U.^2+V.^2+W.^2);
PE = m*g*Z;
%now find the common elements,
C = bsxfun(@eq,KE,PE);
%now plot
figure(1)
subplot(2,1,1)
plot(KE)
hold on
plot(KE(C),'-*')
hold off
%and similar for PE
Hope this is what you were looking for.