MATLAB Answers

0

Is it possible to plot a plot() and area() on same axis

Asked by Vadim Kachan on 17 Jul 2019
Latest activity Commented on by Star Strider
on 17 Jul 2019
Hi,
I am doing data analysis and am trying to plot a data set of y over x with area() and then plot a line of moving avg of y over x with plot() on the same axis. currently it doesn't work. Meaning i get the second graph vs. both at the same time.
Has anyone come up with a solution for this?
y1 = B57(x,2);
Avg1 = movmean(y1,7)
area(PlotAX1,1:length(B57),y1);
area(PlotAX1,1:length(B57),Avg1)

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Star Strider
on 17 Jul 2019
 Accepted Answer

Use the hold function:
B57 = rand(1, 100); % Create ‘B57’
y1 = B57;
PlotAX1 = axes; % Create ‘PlotAX1’
Avg1 = movmean(y1,7);
area(PlotAX1,1:length(B57),y1);
hold on
area(PlotAX1,1:length(B57),Avg1)
hold off

  2 Comments

That's perfect. For second plot i actually needed plot(). I plugged that in and it worked perfectly!

Sign in to comment.