How to plot stacked plot horizontally parallel to each other?
조회 수: 9 (최근 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!