How to plot stacked plot horizontally parallel to each other?

9 ビュー (過去 30 日間)
Dolly More
Dolly More 2022 年 8 月 16 日
回答済み: Narvik 2024 年 9 月 4 日
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 日
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 Center および File ExchangeLine Plots についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by