필터 지우기
필터 지우기

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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by