colorbar problem in surf plot?

5 次查看(过去 30 天)
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2021-8-18
编辑: darova 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).
Please help

回答(1 个)

Simon Chan
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 个评论
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2021-8-18
Thanks Simon Chan,
But graph has 3 Dimensions.
F_cap is there as the 3 dimensions and colorbar should represent the range of values of F_cap using different color. ( In this figure, colorbar range is from 0 to 800 but in my graph plot, F_cap range is from 1 * 10^8 to 3*10^8).
Colorbar should specify ranges of F_cap. But it showing fixed range from 0 to 800 irrespective of range of 3 Dimension.
I tried below code: [it working but problem is with colorbar range and rotation]
[tp,t] = meshgrid(0:2:40,1:21);
surf(tp,t,F_cap,C);
xlabel('Tx_power (dBm)')
ylabel('simulated positions')
zlabel('Throughput in (MBps)');
colorbar;
Can you also help me in rotating graph to anti-clockwise direction so that Tx_power came in horizontal direction, Position in vertical direction and F_cap in upward direction ?
Simon Chan
Simon Chan 2021-8-18
编辑: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;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by