# colorbar problem in surf plot?

2 ビュー (過去 30 日間)
SANDEEP SINGH RANA 2021 年 8 月 18 日

I want to plot 3D graph using 3 parameters but there is error in plotting colorbar. Matrix size of parameters and code to plot graph is as follow:
Tx_power =0:2:40; 1*21 Matrix size
Position =1:21; 1*21 Matrix size
F_cap = 21*21; Matrix size
C= Tx_power.* Position;
figure;
surf(Tx_power,Position,F_cap, C);
colorbar;
Error is:
Colorbar is not ploting and if i remove colorbar, it is working fine. And if colobar is ploting then, it is not ploting graph(i.e. F_cap parameter).

サインインしてコメントする。

### 回答 (1 件)

Simon Chan 2021 年 8 月 18 日
I guess the code should be like that:
Tx_power =0:2:40; %1*21 Matrix size
Position =1:21; %1*21 Matrix size
%F_cap = 21*21; % Matrix size (Not use)
[X,Y]=meshgrid(1:21,1:21); % Make a grid with size 21x21
C= Tx_power(X).*Position(Y); % Calculate C which in 2D, previous is 1D only
figure;
surf(Tx_power,Position, C);
colorbar;
##### 2 件のコメント表示非表示 1 件の古いコメント
Simon Chan 2021 年 8 月 18 日
Try the following, hope this is what you want.
[t,tp] = meshgrid(1:21,0:2:40); % (Edit) Added this line after switching between x & y
surf(t,tp,F_cap);
ylabel('Tx_power (dBm)')
xlabel('simulated positions')
zlabel('Throughput in (MBps)');
colorbar;

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by