How to make two plots happen at the same time on two different axes?

35 ビュー (過去 30 日間)
William Fantin
William Fantin 2019 年 5 月 17 日
編集済み: Adam Danz 2019 年 5 月 22 日
Hello,
My problem is I have two graphs that draw things out at the same time, but they are on different axes. I want them to run in sync with each other so you can see at the same time. As of now one gets drawn out, then after that is done the other starts plotting its points.
Any help would be appreciated!
Thanks
  3 件のコメント
William Fantin
William Fantin 2019 年 5 月 18 日
編集済み: William Fantin 2019 年 5 月 18 日
Hmmm, I was thinking this, but I guess I dont know how to specify that I want one on a certain plot and want the other on a different plot?
Lets say I have this code:
V=linspace(-5,5)
for k=V:length(V)
y=sin(V)
plot(y,'r')
w=cos(V)
plot(w,'b')
end
How would I go about plotting the w and y on different axes in a gui?
Thank you!
Edit: I just re-read your post and I do not know about updates.
Walter Roberson
Walter Roberson 2019 年 5 月 18 日
Search for tag:always-parent in the search box

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2019 年 5 月 18 日
編集済み: Adam Danz 2019 年 5 月 22 日
Here's a demo to follow. It creates two axes that display the time course of a sine and cosine wave. Run it, step through it to understand what's going on, and I'd be glad to address any questions.
% Create data for both axes
x = -pi:.05:pi;
y1 = sin(x);
y2 = cos(x);
% Set up figure(s)
% Note: A lot of this section would be more efficiently done by looping through
% both axes instead of having duplicate commands.
figure
s1 = subplot(2,1,1);
s2 = subplot(2,1,2);
ylabel(s1,'sin(x)')
ylabel(s2,'cos(x)')
xlim(s1,[min(x),max(x)]);
xlim(s2,[min(x),max(x)]);
ylim(s1,[min(y1),max(y1)]);
ylim(s2,[min(y2),max(y2)]);
hold(s1,'on');
hold(s2,'on')
grid(s1,'on')
grid(s2,'on')
% Plot empty lines that will be updated within the loop
% Note: In this exmaple I could have used the real x values below but
% I wanted to show how you update them within the loop.
p1 = plot(s1,nan(size(x)),nan(size(y1)),'-o');
p2 = plot(s2,nan(size(x)),nan(size(y2)),'-o');
% Update each iteration
for i = 1:length(x)
% Update values
p1.XData(i) = x(i);
p1.YData(i) = y1(i);
p2.XData(i) = x(i);
p2.YData(i) = y2(i);
% Update axes
drawnow
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by