フィルターのクリア

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

2 ビュー (過去 30 日間)
Bryan
Bryan 2017 年 12 月 3 日
編集済み: KL 2017 年 12 月 3 日
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

採用された回答

KL
KL 2017 年 12 月 3 日
編集済み: KL 2017 年 12 月 3 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by