Effacer les filtres
Effacer les filtres

How do I tell Matlab to Label the point where my subplots are equal?

2 vues (au cours des 30 derniers jours)
Bryan
Bryan le 3 Déc 2017
Modifié(e) : KL le 3 Déc 2017
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

Réponse acceptée

KL
KL le 3 Déc 2017
Modifié(e) : KL le 3 Déc 2017
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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by