How to make surf plot have different x scales?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there,
I have plotted a 2D graph using the surf(x,t,w) function first and then using the view(2) commend. The W is a 2000x11matrix. x denotes space and is the 1x11 vector. t denotes time and is the 1x2000 vector. Now I want to rescale space x. For each time t, x is rescaled differently. For example, when t=t_1, x is rescaled to 1.2x (each element in the vector x is multiplied by 1.2); when t=t_2, x is rescaled to 1.5x (each element in the vector x is multiplied by 1.5); and so on. How can I achieve this? Any help would be appreciated! Attached is the graph I get.
댓글 수: 0
채택된 답변
Voss
2023년 11월 19일
% define t,x,W variables:
Nx = 11;
Nt = 2000;
W = (Nx:-1:1).*(Nt:-1:1).'/4500;
t = linspace(0,200,Nt);
x = linspace(0,1,Nx)
% plot original:
figure
surf(x,t,W,'EdgeColor','none')
view(2)
xlabel('x')
ylabel('t')
colormap(jet())
colorbar
title('original')
% generate factors to multiply x by, one for each element of t:
x_factor = 1.2+0.3*(0:Nt-1) % 1.2, 1.5, and so on
% make matrices called tt (from t) and xx (from x and x_factors)
% t gets replicated:
tt = repmat(t(:),1,Nx);
% x gets multiplied by the factors:
xx = x.*x_factor(:)
% plot rescaled result:
figure
surf(xx,tt,W,'EdgeColor','none')
view(2)
xlabel('x')
ylabel('t')
colormap(jet())
colorbar
title('rescaled')
댓글 수: 2
Voss
2023년 11월 20일
You're welcome!
The variable W I have defined is just some matrix I made up, since I don't have your W.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!