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!