How to plot stacked plot horizontally parallel to each other?

12 次查看(过去 30 天)
I tried using horizontal stacked plot using the example given in the link as
https://www.mathworks.com/matlabcentral/fileexchange/53620-stackedplot-a-quick-way-to-plot-without-lines-overlapping
N = 4;
mu = 2*rand(1,N);
sigma = [1 0.1 10 1];%rand(1,N);
t = 1:100;
x = bsxfun(@plus,randn(100,4)*diag(sigma),mu);
subplot(1,2,1)
stackedplot(x,t)
subplot(1,2,2)
stackedplot(t,x)
But I didn't get the second plot and got an error as
Error using stackedplot (line 76)
Expected x to be a vector.
Please let me if its possible to do with stacked plots.

回答(1 个)

Narvik
Narvik 2024-9-4,10:44
Hi Dolly,
As per my understanding, you are facing an error while trying to use the "stackedplot" function from File Exchange.
The error arises because "stackedplot" function expects the first argument to be a vector (x-axis) and the second to be a matrix (y-axis).
To create both vertical and horizontal stacked plots, ensure inputs are correctly formatted.
Refer to the following code:
N = 4;
mu = 2 * rand(1, N);
sigma = [1 0.1 10 1];
t = 1:100;
x = bsxfun(@plus, randn(100, 4) * diag(sigma), mu);
subplot(1, 2, 1)
stackedplot(t, x) % Correct: x-axis vector, y-axis matrix
subplot(1, 2, 2)
stackedplot(t, x') % Transpose x for horizontal stacking effect
Ensure 't' is a vector and 'x' is a matrix with columns representing data series. Transposing 'x' in the second plot simulates horizontal stacking.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by