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.
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!