Stacked plot /waterfall plots to visulaise figures

조회 수: 43 (최근 30일)
Ramesh Bala
Ramesh Bala 2021년 9월 10일
댓글: Ramesh Bala 2021년 9월 13일
I have in total 6 signals and would like to see all in a single plot.Since all having same X axis and Y axis (shall normalise it).
How shall I see all in a single waterfall plot?
Thanks in advance.
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
%combined plot
plot(t,e(:,1),'r-',t,e(:,2),'g-',t,e(:,3),'b-',t,e(:,4),'c-',t,e(:,5),'m-',t,e(:,6),'y-');
xlabel('Time (s)'); ylabel('Strain');
legend('5','10','20','30','40','50');

채택된 답변

Dave B
Dave B 2021년 9월 10일
편집: Dave B 2021년 9월 10일
If you want to put these data into a waterfall, you can do waterfall(e') but that won't get your time axis correct. Using meshgrid is an easy way to get x and y values in the right shape for waterfall (or mesh)
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
n = [5 10 20 30 40 50]; % guessing from legend
[xi,yi] = meshgrid(t,n);
waterfall(xi,yi,e')
  댓글 수: 4
Dave B
Dave B 2021년 9월 11일
These aren't so difficult, it's just adding an offset to each line and then you can use plot (as you did originally).
When I've had to do this kind of thing I find it easier to do a bit of rescaling (i.e. make things go between 0 and 1) and then add a fixed offset rather than computing the offsets. It's really a matter of preference. The function rescale is awesome for this, it'll do your whole matrix by default which is a nice way to preserve the relationship between heights. If you want them all to take the same range you'll have to adjust your strategy a little.
One thing that you lose from stackedplot is the separate y axis labels. I imagine this as a hierarchy - a 'which line' followed by a 'units in that line'. In my experience in these plots I often don't care about specific y values, or I can include a little scalebar to indicate the y scale. Below I just label which line it is
t=[0:.01:6]*1e-5;
e=zeros(length(t),6);
e(200:end,1)=12.5*cos(1.3e6*t(200:end) ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,2)=11.8*cos(1.3e6*t(200:end)+pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,3)= 8*cos(1.3e6*t(200:end)-pi/2).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,4)= 6.2*cos(1.3e6*t(200:end)+pi ).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,5)= 7.2*cos(1.3e6*t(200:end)+pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
e(200:end,6)= 8.2*cos(1.3e6*t(200:end)-pi/3).*(sin((t(200:end)-2e-5)*7.8e4)).^2;
offset_e=bsxfun(@plus,rescale(e),1:6);
% bsxfun might feel a little cryptic, an alternative is:
% offset_e = rescale(e) + repmat(1:6,height(e),1);
plot(t,offset_e,'LineWidth',1)
yticks(offset_e(1,:))
yticklabels(1:6)
axis padded
box off
Ramesh Bala
Ramesh Bala 2021년 9월 13일
Thanks Dave

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by