How to make surf plot have different x scales?

2 ビュー (過去 30 日間)
Sharon
Sharon 2023 年 11 月 19 日
コメント済み: Voss 2023 年 11 月 20 日
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.

採用された回答

Voss
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)
x = 1×11
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
% 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
x_factor = 1×2000
1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3.0000 3.3000 3.6000 3.9000 4.2000 4.5000 4.8000 5.1000 5.4000 5.7000 6.0000 6.3000 6.6000 6.9000 7.2000 7.5000 7.8000 8.1000 8.4000 8.7000 9.0000 9.3000 9.6000 9.9000
% 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(:)
xx = 2000×11
0 0.1200 0.2400 0.3600 0.4800 0.6000 0.7200 0.8400 0.9600 1.0800 1.2000 0 0.1500 0.3000 0.4500 0.6000 0.7500 0.9000 1.0500 1.2000 1.3500 1.5000 0 0.1800 0.3600 0.5400 0.7200 0.9000 1.0800 1.2600 1.4400 1.6200 1.8000 0 0.2100 0.4200 0.6300 0.8400 1.0500 1.2600 1.4700 1.6800 1.8900 2.1000 0 0.2400 0.4800 0.7200 0.9600 1.2000 1.4400 1.6800 1.9200 2.1600 2.4000 0 0.2700 0.5400 0.8100 1.0800 1.3500 1.6200 1.8900 2.1600 2.4300 2.7000 0 0.3000 0.6000 0.9000 1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3.0000 0 0.3300 0.6600 0.9900 1.3200 1.6500 1.9800 2.3100 2.6400 2.9700 3.3000 0 0.3600 0.7200 1.0800 1.4400 1.8000 2.1600 2.5200 2.8800 3.2400 3.6000 0 0.3900 0.7800 1.1700 1.5600 1.9500 2.3400 2.7300 3.1200 3.5100 3.9000
% plot rescaled result:
figure
surf(xx,tt,W,'EdgeColor','none')
view(2)
xlabel('x')
ylabel('t')
colormap(jet())
colorbar
title('rescaled')
  2 件のコメント
Sharon
Sharon 2023 年 11 月 20 日
Hi Voss, thank you very much for answering my question. It is very helpful. I have a question. What is the variable W you defined? Could you explain it a little? Thanks.
Voss
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 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by